Work with arrays and their powerful built-in methods — map, filter, reduce, and more.
1const languages = ["Python", "JavaScript", "Java", "C++"];2 3console.log(languages[0]); // Python4console.log(languages.length); // 45console.log(languages.at(-1)); // C++ (last element)6 7// Modify8languages.push("Go"); // Add to end9languages.unshift("Rust"); // Add to start10console.log(languages);Python 4 C++ ["Rust", "Python", "JavaScript", "Java", "C++", "Go"]
1const prices = [10, 20, 30, 40, 50];2 3// map — transform each element4const doubled = prices.map(p => p * 2);5console.log(doubled); // [20, 40, 60, 80, 100]6 7// filter — keep elements that pass a test8const expensive = prices.filter(p => p > 25);9console.log(expensive); // [30, 40, 50]10 11// reduce — accumulate into one value12const total = prices.reduce((sum, p) => sum + p, 0);13console.log(total); // 150[20, 40, 60, 80, 100] [30, 40, 50] 150