Skip to content
techsnow

Arrays & Objects

Arrays

An array is an ordered list of values. Positions (indexes) start at 0.

const fruits = ["apple", "banana", "mango"];

console.log(fruits[0]);      // "apple"
console.log(fruits.length);  // 3
console.log(fruits.at(-1));  // "mango" (last item)

fruits.push("orange");       // add to the end
fruits.pop();                // remove from the end
fruits.unshift("grape");     // add to the start
fruits.shift();              // remove from the start

console.log(fruits.includes("banana")); // true
console.log(fruits.indexOf("mango"));   // 2
console.log(fruits.join(", "));         // "apple, banana, mango"