Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Create and Retrieve Array in Javascript?

    • 0
    • 5
    • 3
    • 1
    • 0
    • 0
    • 0
    • 0
    • 203
    Comment on it

    If you want to store multiple values in a single variable javaScript arrays are used.
    There are few ways to store values in array in javascript which are mentioned below.

    First way:

    HTML:

    <div id="fruitList"></div>
    

    Javascript:

    var fruits = ["Apple", "Orange", "Grapes"];
    document.getElementById("fruitList").innerHTML = fruits;
    

    Second way:

    HTML:

    <div id="fruitList"></div>
    

    Javascript:

    var fruits = [ ]
    
    fruits[0] = "Apple";
    fruits[1] = "Orange";
    fruits[2] = "Grapes";
    
     document.getElementById("fruitList").innerHTML = fruits;
    

    Third way

    HTML:

    <div id="fruitList"></div>
    

    Javascript:

    var fruits = {"first":"Apple","second":"Orange","third":"Grapes"};
    
    document.getElementById("fruitList").innerHTML = fruits["first"];
    document.getElementById("fruitList").innerHTML = fruits["second"];
    document.getElementById("fruitList").innerHTML = fruits["third"];
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: