“Klon AjavaScript -Objekt” Code-Antworten

Klonobjekt in JS

var student = {name: "Rahul", age: "16", hobby: "football"};

//using ES6
var studentCopy1 = Object.assign({}, student);
//using spread syntax
var studentCopy2 = {...student}; 
//Fast cloning with data loss
var studentCopy3 = JSON.parse(JSON.stringify(student));
JavascriptNinja

Klon AjavaScript -Objekt

var sheep={"height":20,"name":"Melvin"};
var clonedSheep=JSON.parse(JSON.stringify(sheep));

//note: cloning like this will not work with some complex objects such as:  Date(), undefined, Infinity
// For complex objects try: lodash's cloneDeep() method or angularJS angular.copy() method
Grepper

Ähnliche Antworten wie “Klon AjavaScript -Objekt”

Fragen ähnlich wie “Klon AjavaScript -Objekt”

Weitere verwandte Antworten zu “Klon AjavaScript -Objekt” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen