Spread
Modern way to work with arrays
// Copy an array
let original = [1, 2, 3];
let copy = [...original];
console.log(copy); // [1, 2, 3]
// Merge arrays
let first = [1, 2];
let second = [3, 4];
let combined = [...first, ...second];
console.log(combined); // [1, 2, 3, 4]
// Add elements
let numbers = [2, 3];
let expanded = [1, ...numbers, 4];
console.log(expanded); // [1, 2, 3, 4]
Sort, without affecting the original array
let fruits = ["orange", "apple", "banana"];
let sortedFruits = [...fruits].sort();
console.log(sortedFruits);