Skip to content

Extract / Copy Methods

Returns a shallow copy of part of an array.

const arr = [10, 20, 30, 40];
const part = arr.slice(1, 3);
// [20, 30]

Time: O(k) Mutates original? No

Interview trap: slice does NOT modify


Merges arrays.

const a = [1, 2];
const b = [3, 4];
const result = a.concat(b);
// [1, 2, 3, 4]

Time: O(n + m) Mutateginal? No