Javascript Array:
var obj = [];
obj.push = 'Some VALUE'; Or var obj = ['SomeVALUE', 1, 2];
now to access them use obj[0] -- 0 stands the index No.
***********************************************
JSON Array and manipulations:
Example
var obj = { name : value, anotherName : anotherValue }; // if JS Variable used
var obj = { 'name' : 'value', 'anotherName' : 'anotherValue' }; // if JS Strings are used
Or Else
ips[ipId] = {};
ips[ipId]['name'] = value;
ips[ipId]['anotherName'] = anotherValue;
now -
JSON.stringify(object); // gets you the string of the JSON Object
// No need to parse, no need to use JSON.parse as the variable holds the JSON Object only.
if you want to create a JSON Object from string or reverse engineer JSON.stringify() Method then use JSON.parse();
Also, You can use string variables to specify the names of the properties:
var name = 'name'; // name is variable - changing its value often
obj[name] = value; // note that their are no single quotes near name variable;
name = 'anotherName';
obj[name] = anotherValue;a
No comments:
Post a Comment