Answers for "adding to an array without mutating the original array"

0

adding to an array without mutating the original array

// since we will not be mutating, 
// use const
const arr1 = ['a', 'b', 'c', 'd', 'e'];

const arr2 = [...arr1, 'f']; // ['a', 'b', 'c', 'd', 'e', 'f']
const arr3 = ['z', ...arr1]; // ['z', 'a', 'b', 'c', 'd', 'e']
Posted by: Guest on April-21-2021

Code answers related to "adding to an array without mutating the original array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language