24
JSON + Javascript Cheatsheet.
var myArr = {
key: value,
key2: value2
};
var myJSON = JSON.stringify(myArr);
Result:
'{"key":"value","key2":"value2"}';
var myJSON = '{"key":"value","key2":"value2"}';
var myArr = JSON.parse(myJSON);
Result:
{
key: value,
key2: value2
};
var myJSON = '{"key":"value","key2":"value2"}';
var myArr = JSON.parse(myJSON);
var jsonLength = myArr.length;
Result:
2
var myJSON = '{"key":"value","key2":"value2"}';
var myArr = JSON.parse(myJSON);
myArr.forEach(function(nowItem) {
// Do things here
})
var myJSON = '{"key":"value","key2":"value2"}';
var myArr = JSON.parse(myJSON);
console.log(myArr["key2"]);
Result:
value2
var myJSON = '{"key":"value","key2":"value2"}';
var myArr = JSON.parse(myJSON);
myArr["key3"] = "value3";
myArr result:
{
key: "value",
key2: "value2",
key3: "value3"
}
var myJSON = '{"key":"value","key2":"value2"}';
var myArr = JSON.parse(myJSON);
delete myArr["key2"];
myArr result:
{
"key": "value"
}
24