Thursday, May 17, 2012

Obray Curry: A dish using Obect and Array- II

Today is another interesting find:

console.clear();

var a ={};
a.p1 = "kiazen";
a["p2"] = "krook";
a[0] = 10;
a[1] = 20;
a[2] = 30;
a[3] = 40;
console.log(a)
console.log(JSON.stringify(a));


console.clear();

var a =[];
a.p1 = "kiazen";
a["p2"] = "krook";
a[0] = 10;
a[1] = 20;
a[2] = 30;
a[3] = 40;
console.log(a)
console.log(JSON.stringify(a));

The catch is
var a= []
 //=> this implies 'a' as associative array and not oject
or
var a= {};
 //=> this implies 'a' as object.

So my interpretation leads that serialization of javascript object/array depends on the first initialization fo the object.

No comments:

Post a Comment

There was an error in this gadget