Linked Questions
74 questions linked to/from How to Deep clone in JavaScript
14
votes
1
answer
21k
views
javascript - how to clone Array without reference [duplicate]
I'm trying to clone Array to a new one, and I want cloned array has no reference to original copy
I know there're splice and from method, but new array from those methods all has reference to ...
1
vote
1
answer
3k
views
Typescript - Custom type assignment by value [duplicate]
In one of my procedures I need to periodically reset a custom type, but I noticed that in TypeScript (and I think in JavaScript too maybe), when I assign a variable of a custom type to another ...
0
votes
1
answer
2k
views
How to deep clone object with functions in Javascript? [duplicate]
I need to "load" content from my const objects, but the problem is that when I use content = levels[level], and then modify content, levels[level] is modified too, so if I load it again, ...
2
votes
1
answer
644
views
How can we Recursively remap the Nested Array in Javascript? [duplicate]
Looking for recursively remap the nested array in TypeScript / Javascript. I have an array that has parent and children objects and wants to clone with a blank array with only has children and ...
0
votes
1
answer
188
views
Deep clone two array in typescript with respect to performance [duplicate]
i am working with date and time. i have calendar and default time slots from 9am to 5pm.
i need to mark checked property to true in timeList parameter by mathcing time from the selectedDatesTiming ...
1
vote
1
answer
249
views
How to Prevent Map from Mutating Data in Javascript [duplicate]
I have an object array that looks like this:
rawData:
0: {name: "cat", count: 2}
1: {name: "dog", count: 5}
2: {name: "fish", count: 3}
and I have a translatedData that multiplies the count field by ...
1
vote
1
answer
120
views
How do I deep clone JSON object in javascript [duplicate]
const obj1 = { food: 'pizza', car: 'ford' };
let obj2 = obj1;
In the above example, I want to do deep copy of obj1 in obj2 .
0
votes
1
answer
105
views
JS: Variable is being changed and i can't figure out why [duplicate]
Pardon the title, I have no idea how to describe this. I have a problem where my code changes variables it has no business changing, and I can't figure out why.
The code:
getCalendar (parameters, ...
0
votes
1
answer
57
views
Strange Javascript Variable Function Scope With Loop [duplicate]
I am experiencing some strange behavior when trying to do the following:
Create a base JSON object
Create a for loop and send the base object to a new function to be modified
The new function should ...
1
vote
0
answers
78
views
Deep clone object in Javascript except Object.assign [duplicate]
Object.assign doesn't deep copy an object. considering following code it should print 0 0 0 1 but it is printing 0 0 1 1.
var obj = {
"value": {
"default": 0
}
};
var newo = Object....
0
votes
1
answer
58
views
What is the simplest way to duplicate a threaded Javascript object without using JSON.parse(JSON.stringify(obj)) [duplicate]
I tried again and again to look for a simple way to duplicate a threaded object but unfortunately without success.
Each time I tried to duplicate the threaded object containing additional objects, ...
0
votes
0
answers
41
views
Cloned copy of object is still referenced, arrays within becomes mutable [duplicate]
I have an object which I would like to clone. I would like that the questionsObj always remains the same. In my project I build the questionsObj with a bunch of imports of arrays like this:
import ...
-1
votes
1
answer
49
views
What should we do when we need to clone an object deeply [duplicate]
According with what was sayed on another question:
The spread operator is like Object.assign and does not deeply clone an
object. The reason the JSON thing worked is because you created a
whole ...
5157
votes
67
answers
3.1m
views
What is the most efficient way to deep clone an object in JavaScript?
What is the most efficient way to clone a JavaScript object? I've seen obj = eval(uneval(o)); being used, but that's non-standard and only supported by Firefox. I've done things like obj = JSON.parse(...
1729
votes
12
answers
373k
views
Differences between Lodash and Underscore.js [closed]
Why would someone prefer either the Lodash or Underscore.js utility library over the other?
Lodash seems to be a drop-in replacement for underscore, the latter having been around longer.
I think both ...