logo
Search
showing results for - "adding to an array without mutating the original array"
Debora
17 Nov 2020
1// since we will not be mutating, 
2// use const
3const arr1 = ['a', 'b', 'c', 'd', 'e'];
4
5const arr2 = [...arr1, 'f']; // ['a', 'b', 'c', 'd', 'e', 'f']
6const arr3 = ['z', ...arr1]; // ['z', 'a', 'b', 'c', 'd', 'e']
7
source
similar questions
add multiple class from array javascriptes6 create array of multiplesmultidimensional array push in jqueryconcatenate multiple arrays javascriptfunction mutate the array 28n 2c a 29array reverse without mutatingconcat two arrays each value react typescriptsum of several arraysjavascript merge two array with spread operatorhow to add multiple elements to a new array javascriptmerger douplicate array objectjavascript array multidimensional pushredux merge array of objectsjavascript merge multidimensional arraymerge array no duiplicates js
queries leading to this page
e2 80 9cadding to an array without mutating the original arrayadding to an array without mutating the original arrayadd item to array without mutatingadding to an array without mutating the original array
privacy policyterms of useinstagram
Crafted with  ♥  for everyone

sign in to continue
your answer for
you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content
please ensure to add code which is syntactically corrent and executes properly
sign in to continue
ask question on maxinterview
you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content
please be clear, to the point and respectful
sign in to continue