Extract / Copy Methods
Extract / Copy Methods
Section titled “Extract / Copy Methods”slice()
Section titled “slice()”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
concat()
Section titled “concat()”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