Example 1: list javascript
var fruits = ["Apple", "Banana", "Cherry"];
var books = [];
console.log(fruits[0])
fruits.push("Orange")
fruits[1]="Blueberry"
fruits.splice(0, 1)
fruits.splice(0, 2)
Example 2: javascript array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 3: how to create an array in javascript
let fruits = ['Apple', 'Banana']
console.log(fruits.length)
Example 4: javascript array read object value in array
var events = [
{
userId: 1,
place: "Wormholes Allow Information to Escape Black Holes",
name: "Check out this recent discovery about workholes",
date: "2020-06-26T17:58:57.776Z",
id: 1
},
{
userId: 1,
place: "Wormholes Allow Information to Escape Black Holes",
name: "Check out this recent discovery about workholes",
date: "2020-06-26T17:58:57.776Z",
id: 2
},
{
userId: 1,
place: "Wormholes Allow Information to Escape Black Holes",
name: "Check out this recent discovery about workholes",
date: "2020-06-26T17:58:57.776Z",
id: 3
}
];
console.log(events[0].place);
Example 5: java script arrays
fruits = ["Banana", "Orange", "Apple", "Mango"];
text = "<ul>";
for (i = 0; i < fruits.length; i++) {
text += "<li>" + fruits[i] + "</li>";
}
Example 6: javacript array
[element0, element1, ..., elementN]
new Array(element0, element1[, ...[, elementN]])
new Array(arrayLength)