slice() & concat() in JavaScript
From the JavaScript Array Methods cheat sheet ยท Array Manipulation ยท verified Jul 2026
slice() & concat()
Extract portions and combine arrays without mutation
javascript
// Copy portion of array
const portion = arr.slice(1, 3); // Items at index 1, 2
const last3 = arr.slice(-3); // Last 3 items
const copy = arr.slice(); // Full copy
// Combine arrays
const combined = arr1.concat(arr2, arr3);
const combined = [...arr1, ...arr2]; // Modern way๐ข Essential - Safe array operations
๐ก slice() extracts portion, concat() combines arrays
โก Both return new arrays (immutable)
๐ Negative indices count from end
๐ Use spread [...arr1, ...arr2] as modern concat