score:5
For deep copy try this
let _result = JSON.parse(JSON.stringify(steps));
or
const newArray = steps.map(step => ({...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?
score:0
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.
Source: stackoverflow.com
Related Query
- How can change the clone of an array and not change the original array in reactjs
- How can you check if there is an existing value in the array and not add it another time if so?
- How can i get array of object from this data for state and count in reactjs
- How can I not pass children as props. Instead, nest children between the opening and closing tags on React?
- How can I use Promise.all on an array of objects and then reassign them to the relevant key in a new object?
- How can I change the checkbox styles and icons when hover on it in Material-UI React?
- How to send an email using javascript and not change the window location?
- How can I toggle a class and change the CSS in Nextjs?
- How can I create a button which Fetches image from API and download to the local with using ReactJs
- How to remove selected index of an array from the DOM and reflect the change in React state?
- I am trying to animate an object with css in react and change the animation (timing) dynamically, how can I set the style after animation end?
- ReactJS and DraftJS, how to change font size on the fly?
- React - How can I access a particular position in the array, and then change it?
- How can I make useEffect not return the initial value? I keep getting empty array when I'm trying to pass an array of objects into a component
- How can I change the style after mapping the array with js?
- How can I change the array key value before passing to the state in react?
- In React How can I fetch data and render a single object in a states array without mapping the whole thing?
- How i can filter through an Array and return the correct property?
- How can I get a component to update on path change while using the same route and component?
- ReactJS & Material-UI: How to highlight just content inside Material-UI's <Dialog> and not the whole page?
- Clicking the submit button to go to the next tab only changes the URL but not the tab and the component itself. How can I fix?
- How can I shuffle an array of objects on page render and map over the shuffled array without console warning of "two children with the same key"?
- how i can display some UI e.g circle and when data arrives i can change the color of specific circle?
- How can I compare two arrays of objects and add new key to an objects in the second array
- How can I extract a nested array of objects and put them in the core array?
- How can I change the value of an object in an array in react redux when the action is called?
- How To Change the Color and Font Of Labels of Bar Chart Using ChartistJs Library with ReactJs
- React: same component reappearing multiple times in the app, how can I make sure that all states are captured accurately and not just the last?
- How can I get all the object inside an object which is present inside an array and add the result into another array
- How can I change the URL for a React app that I'm hosting myself and to which I forward a domain?
More Query from same tag
- Map Child within JSX Component Not Appearing
- React / Rails API Image Uploading
- What is the correct way to add to an array with splice in react
- Way to remove string concat in Oracle-db (Nodejs)
- React Hooks Rendered more hooks than during the previous render
- AJAX requests from a React component
- Why react-datepicker is not selecting correct date?
- Node.js res.json() and res.send(), not working but still able to change status code
- make input label stay up when the input in not focus
- How to appendChild custom component using React JS and Typescript?
- Stop Function being called multiple times when scrolling
- Expo, java.net.SocketTimeoutException:failed to connect
- Union of Polymorphic and Non-Polymorphic Types
- Reactjs cypress on firefox: Error: Could not find url target in browser about:blank. Targets were []
- Integration in React with Ruby on Rails.
- how to use preventDefault() While passing variable in react?
- CSS grid, Day.js : How do I create a calendar that shows the current week's dates?
- useEffect empty array callback does not work
- React access setState in array map
- Strip API error - Indian regulation law causing payment error in React App
- how to style same element with different CSS properties in styled-components
- How to allow only double numbers in input React js
- React NavDropdown hides on click of any MenuItem
- How to pass data from state in Iframe and access the state values from other project(React.js)?
- Call a method in props inside a function with the same name
- Add path when webpack creates static asset files react, create react app
- Why React event handler is not called on dispatchEvent?
- ReactJS component rendering and how to append elements to the div the component is mounted on
- validateDOMNesting warning React
- How can I get the credential from linkWithPopup when it has an error?