DEV Community

Discussion on: Best way to copy an object in JavaScript?

Collapse
 
lexlohr profile image
Alex Lohr • Edited

Good ol' var copy = {}; for (var item in obj) { obj.hasOwnProperty(item) && (copy[item] = obj[item]); } approach works most of the times.

About those cases when this doesn't work: maybe you're solving the wrong problem.