Accepted answer

For deep copy try this

  let _result = JSON.parse(JSON.stringify(steps));


  const newArray = => ({...step}));

spread syntax doesn't give a deep copy

Deep copy

A deep copy means actually creating a new array and copying over the values, since whatever happens to it will never affect the origin one.

For more clarification and the better understanding, you can refer How do you clone an Array in Javascript?


Parsing and Un-Parsing can be quite a performance hit depending on the situation, One convenient alternate way would be that if you use 'Lodash' in your project you can simply use cloneDeep like so:

const newArr = _.cloneDeep( steps );

This returns a new array, leaving the original one untouched.

Related Query

More Query from same tag