DEV Community

Discussion on: Copying objects in JavaScript

Collapse
 
papayankey profile image
Benneth Yankey • Edited

I surely will use the recursion approach too. However, typeof is sloppy in terms of differentiating between array and object. In order to truly check for object type, I will go with plain old trick below:

function isObject(value) {
  return Object.prototype.toString.call(value) === '[object Object]';
}
Thread Thread
 
ip127001 profile image
Rohit Kumawat

Cool. I missed that part. Thanks for the solution.

I was just giving some information about how can we make such a function to deep copying with help of recursion. So, there might be some more improvements that can be implemented to make it handle every case.

But Great Insight!

Thread Thread
 
bernardbaker profile image
Bernard Baker

That's a good point.