create and assign array in js code example
Example 1: javascript array
//create an array like so:
var colors = ["red","blue","green"];
//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 2: how to read an array in javascript in HTML5
<body>
<h1>Creating Arrays</h1>
<h2>Regular:</h2>
<script language="JavaScript">
var Colors = new Array();
Colors[0] = "Blue";
Colors[1] = "Green";
Colors[2] = "Purple";
document.write(Colors);
</script>
<h2>Condensed:</h2>
<script language="JavaScript">
var Colors = new Array("Blue", "Green", "Purple");
document.write(Colors);
</script>
<h2>Literal:</h2>
<script language="JavaScript">
var Colors = ["Blue", "Green", "Purple"];
document.write(Colors);
</script>
</body>