i use obj.hasownproperty judge whether object has property, when replaced obj[prop] !== undefined , not normal implementation, ask, why behind method can not use it? object.hasownproperty(prop); object[prop] !== undefined; obj[prop] !== undefined wrong 2 reasons: you can explicitly set property undefined , obj[prop] = undefined; . obj.hasownproperty(prop) return true in case. obj[prop] follow prototype chain, return property that's inherited. obj.hasownproperty(prop) returns true if property exists directly in object, returns false inherited properties.
i'm trying upgrade existing json structure more complex one. the original idea bunch of x animals , each 1 having bunch of caracteristics: animals animal 1 claws:4 eyes:2 animal 2 claws:0 eyes:6 etc. the json this: { "animals":[ {"claws":"4", "eyes":"2"}, {"claws":"0", "eyes":"6"}, etc. ] } so can see, don't name each animal object, caracteristics of animal element of array. can use them in loop animals[x].claws now want add nest each animal, like: animals animal 1 head eyes:2 ears:2 body claws:4 tails:1 legs:4 animal 2 head eyes:6 ears:0 body claws:0 tails:0 legs:8 but didn't manage without naming each animal object (with same name "animal") , using arrays what's in animal: { "animals":[ {"animal":[ {"head": ...
Comments
Post a Comment