Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
An array is like a numbered list where you can store multiple items. Perfect for shopping lists, todo lists, or any collection of similar things!
const items = [item1, item2, item3];Put items inside square brackets [ ], separated by commas
Different types of arrays you can create
Get items from an array using their index
array.push(item)Add to end
array.unshift(item)Add to beginning
array.pop()Remove from end
array.shift()Remove from beginning
Modify arrays with push, pop, shift, and unshift
includes()Check if item exists
arr.includes(5) → trueindexOf()Find position of item
arr.indexOf(5) → 2join()Join into string
arr.join(', ') → "a, b, c"slice()Copy part of array
arr.slice(1, 3) → [b, c]reverse()Reverse order
arr.reverse() → [3, 2, 1]sort()Sort items
arr.sort() → [1, 2, 3]Essential methods for working with arrays
for (const item of array) {
console.log(item);
}Gets each value directly
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}Gives you position number too
Different ways to go through all items
Calculate total price from array of items
Store multiple items: [1, 2, 3]
First item is array[0], not array[1]
Add to end, pop() removes from end
Easiest way to go through all items