javascript array in array code example
Example 1: javascript element in array
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var n = fruits.includes("Mango");
Example 2: javascript array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 3: js in_array
var a = [1, 2, 3];
a.includes(2);
a.includes(4);
Example 4: array ub js
var fruits = ['Apple', 'Banana'];
Example 5: javascript multidimensional array
var items = [
[1, 2],
[3, 4],
[5, 6]
];
console.log(items[0][0]);
console.log(items[0][1]);
console.log(items[1][0]);
console.log(items[1][1]);
console.log(items);
Example 6: set element at index javascript array and create new array
const items = [1, 2, 3, 4, 5]
const insert = (arr, index, newItem) => [
...arr.slice(0, index),
newItem,
...arr.slice(index)
]
const result = insert(items, 1, 10)
console.log(result)