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)