Loading workspace environment...
Store and manage ordered collections of items using zero-indexed arrays.
const list = ["A", "B", "C"];Creates an array with 3 elements.list[0]Accesses the first element (zero-indexed).list.lengthReturns the number of elements in the array.list.push("D");Adds an element to the end of the array.const fruits = ["Apple", "Banana", "Cherry"];
console.log("First fruit:", fruits[0]);
console.log("Total fruits count:", fruits.length);
// Add a new fruit
fruits.push("Dragonfruit");
console.log("After push:", fruits);
// Iterate through all items
console.log("--- Shopping List ---");
for (let i = 0; i < fruits.length; i++) {
console.log((i + 1) + ". " + fruits[i]);
}First fruit: Apple
Total fruits count: 3
After push: [ 'Apple', 'Banana', 'Cherry', 'Dragonfruit' ]
--- Shopping List ---
1. Apple
2. Banana
3. Cherry
4. Dragonfruitfruits[0]Accesses the element at index 0.fruits.push("Dragonfruit");Adds element to the end of the array.const items = ["A", "B", "C"];
console.log(items[3]); // undefined!console.log(items[2]); // Prints "C"Architectural Explanation: In a 3-item array, valid indices are 0, 1, and 2. Index 3 does not exist and returns undefined.
const scores = [10, 20, 30];
console.log(scores[1]);Write a loop that sums all numbers in an array [10, 20, 30, 40] and logs the average.