A JavaScript Array is a special type of object used to store multiple values in a single variable. Arrays are zero-indexed and dynamic (can grow or shrink).
Note: Arrays can contain elements of any type โ numbers, strings, objects, other arrays, or mixed types.
let fruits = ["Apple", "Banana", "Mango"]; let numbers = [10, 20, 30, 40]; let mixed = [1, "hello", true];
Open your browser console and try this code:
let colors = ["Red", "Green", "Blue"]; console.log(colors[0]); // Red console.log(colors.length); // 3 colors.push("Yellow"); // Add new item console.log(colors); // ["Red", "Green", "Blue", "Yellow"] colors.pop(); // Remove last item
push()
โ Adds item to endpop()
โ Removes item from endshift()
โ Removes item from startunshift()
โ Adds item to startslice(start, end)
โ Extracts a portionsplice(start, deleteCount)
โ Removes or replaces elementsindexOf()
โ Finds index of itemincludes()
โ Checks if item existsjoin()
โ Converts to stringlet numbers = [10, 20, 30]; numbers.forEach(function(num) { console.log(num); }); // Using arrow function numbers.forEach(num => console.log(num));
typeof [] === "object"
Array.isArray()
to check if a variable is an array.map()
, filter()
, and reduce()
for powerful array operations.Try This:
Type ["one", "two", "three"].join(" | ")
in the console and observe how it combines the array into a single string.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!