how to write an array js code example
Example 1: how to make an array in javascript
var names = ["Sanjith", "Pranav", "Aadya", "Saharsh"]
Example 2: how to create array in javascript
/*
Array class is a global object that is used
in the construction of arrays
See - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
*/
let array_1 = new Array(2);
arr.push("James");
arr.push("Fred");
let array_2 = ["James", "Fred"];
Example 3: how to read an array in javascript in HTML5
<body>
<h1>Creating Arrays</h1>
<h2>Regular:</h2>
<script language="JavaScript">
// Create the array.
var Colors = new Array();
// Fill the array with data.
Colors[0] = "Blue";
Colors[1] = "Green";
Colors[2] = "Purple";
// Display the content onscreen.
document.write(Colors);
</script>
<h2>Condensed:</h2>
<script language="JavaScript">
// Create the array and fill it with data.
var Colors = new Array("Blue", "Green", "Purple");
// Display the content onscreen.
document.write(Colors);
</script>
<h2>Literal:</h2>
<script language="JavaScript">
// Create the array and fill it with data.
var Colors = ["Blue", "Green", "Purple"];
// Display the content onscreen.
document.write(Colors);
</script>
</body>