javascript var array code example
Example 1: javascript array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 2: javascript array
var food = ["cake", "apple", "Ice-Cream"]
var Number = [Math.floor(Math.random() * food.length)];
console.log(logammounts[woodloot])
Example 3: how to create an array in javascript
let fruits = ['Apple', 'Banana']
console.log(fruits.length)
Example 4: array javascript
var fruits = ['Apple', 'Banana'];
console.log(fruits.length);
var first = fruits[0];
var last = fruits[fruits.length - 1];
fruits.forEach(function(item, index, array) {
console.log(item, index);
});
var newLength = fruits.push('Orange');
var last = fruits.pop();
var first = fruits.shift();
var newLength = fruits.unshift('Strawberry')
fruits.push('Mango');
var pos = fruits.indexOf('Banana');
var removedItem = fruits.splice(pos, 1);
var vegetables = ['Cabbage', 'Turnip', 'Radish', 'Carrot'];
console.log(vegetables);
var pos = 1, n = 2;
var removedItems = vegetables.splice(pos, n);
console.log(vegetables);
console.log(removedItems);
Example 5: tableau javascript
console.log(arr.0);