best way to clone an object in javascript
var x = {myProp: "value"};
var y = Object.assign({}, x); var x = {key: 'value'}
var y = JSON.parse(JSON.stringify(x))
//this method actually creates a reference-free version of the object, unlike the other methods
//If you do not use Dates, functions, undefined, regExp or Infinity within your objectvar x = {myProp: "value"};
var xClone = Object.assign({}, x);
//Obs: nested objects are still copied as reference.const person = {
firstName: 'John',
lastName: 'Doe'
};
// using spread ...
let p1 = {
...person
};
// using Object.assign() method
let p2 = Object.assign({}, person);
// using JSON
let p3 = JSON.parse(JSON.stringify(person));
Also in JavaScript:
- find particular object from array in js
- detect adblock javascript
- react js materilize
- scroll down hide header jquery
- javascript check if character exists in string
- jquery live notification
- how to give a person a role by id in discord.js
- how to remove an class in javascript
- remove character at index from string javascript
- new map js
- remove curly brackets from stringify javascript
- train function ajax
- onclick react
- adonisjs column default value
- check if string is datestring javascript
- convert array object to string javascript
- react 17 hot reload not working
- js scrollto
- js when key is pressed
- change font js
- node close rabbitmq connection
- js add class
- javascript string return character
- string to JSONobject android