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

More JavaScript tasks

Back to the full JavaScript Array Methods cheat sheet