Question 1. I was wondering why
JSON.parse(JSON.stringify(obj.slice(1, 3))) and
obj.slice(1,3)
give the same nested array of objects as output since obj.slice(1,3)
is not supposed to clone nested objects properly?
Question 2. Is JSON.parse(JSON.stringify(obj.slice(1, 3)))
the right way to deep clone a sub-array?
obj details -
var obj= [{ name: "wfwfwfw.)csdfsd",
tags: [ "dfbdf>>sfdfds", "fsdfsdf&fsfd" ],
newer: { first: "this'one", second: ["that>.one", "another.'one"], third: {something: "some/>fded", newthing: "ddasd..>sqw"} },
final: [ {gh: "ty/fgfg", hj: "rt((ssds"}, {gh: "dqqq...g", hj: "gnm))s"} ]
},
{ name: "wfwfwwwwwwfw.)csdfsd",
tags: [ "dfbdf>>sfdfds", "fsdfsdf&fsfd" ],
newer: { first: "this'one", second: ["that>.one", "another.'one"], third: {something: "some/>fded", newthing: "ddasd..>sqw"} },
final: [ {gh: "ty/fgfg", hj: "rt((ssds"}, {gh: "dqqq...g", hj: "gnm))s"}]
},
{ name: "aa.)csdfsd",
tags: [ "dfbdf>>sfdfds", "fsdfsdf&fsfd" ],
newer: { first: "this'one", second: ["that>.one", "another.'one"], third: {something: "some/>fded", newthing: "ddasd..>sqw"} },
final: [ {gh: "ty/fgfg", hj: "rt((ssds"}, {gh: "dqqq...g", hj: "gnm))s"}]
},
{ name: "nn.)csdfsd",
tags: [ "dfbdf>>sfdfds", "fsdfsdf&fsfd" ],
newer: { first: "this'one", second: ["that>.one", "another.'one"], third: {something: "some/>fded", newthing: "ddasd..>sqw"} },
final: [ {gh: "ty/fgfg", hj: "rt((ssds"}, {gh: "dqqq...g", hj: "gnm))s"}]
}]