Copy a JSON object -
let's have json object:
myjson1={ key1:value1, key2:value2 } myjson2={};
and json object myjson2 when run
myjson2 = myjson1;
all think goes first object equal second. if try use myjson2 this,
var val = myjson2.key1; console.log(val); empty !!!
i have make search , found "proto"
swagin9 right - make sure assignment statement correct. comment on post, don't have enough rep i'll add here - make sure value1 , value2 defined. themselves, don't mean anything. either put them in quotes, make them ints or booleans, etc. or define them variables before instantiating myjson1 make sure mean something. correct assignment statement, you'll still error if json objects defined way right now.
so example, produces error:
myjson1={ key1: value1, key2: value2 } myjson2={}; myjson2 = myjson1; console.log(myjson2.key1);
this not produce error:
myjson1={ key1: "value1", key2: "value2" } myjson2={}; myjson2 = myjson1; console.log(myjson2.key1);
Comments
Post a Comment