JAVASCRIPT iterate JSON structure
by dshilkret
JavaScript
var json = {"@odata.etag":"\"7692275b-eb7f-4aae-9c19-b073e0760aa7,2\"","id":"1","webUrl":"https://dtecho365.sharepoint.com/sites/ServiceNowDev1/Dev1Lib4/DavidShilkretUpdateSetWithRecordsManagementStuffFromSat.xml","[email protected]":"https://graph.microsoft.com/v1.0/$metadata#sites('dtecho365.sharepoint.com%2Cf4695111-a44a-4c06-bb0c-1b9d249b93a4%2C2ea2bdd1-c608-40f4-b63a-d44c45650402')/lists('729c8285-506d-409d-8ca6-023a69795b88')/items('1')/fields/$entity","fields":{"@odata.etag":"\"7692275b-eb7f-4aae-9c19-b073e0760aa7,2\"","id":"1"}};
/* for (var key in ojb) {
// check if the property/key is defined in the object itself, not in parent
if (ojb.hasOwnProperty(key)) {
alert(key, ojb[key]);
//alert("Key is " + key[0].tabID );
}
} */
var count = 1;
var totcount
// https://stackoverflow.com/questions/1078118/how-do-i-iterate-over-a-json-structure
for (var i = 0; i < json.length; i++){
var obj = json[i];
for (var key in obj){
var attrName = key;
var attrValue = obj[key];
//console.log("tabID: "+key.tabID);
//console.log(attrName);
//console.log(attrValue);
//if(attrValue === 1907108604 ){
thisTabID = attrValue;
totcount = count++
console.log("SAME TAB ID: "+attrValue+ "| COUNT: "+totcount);
//}
}
}
console.log("SAME TAB ID: "+thisTabID+ "| COUNT: "+totcount);
/***************************************/
// GOOD ONE
for (var key in json) {
if (json.hasOwnProperty(key)) {
//alert(json[key].tabID);
//alert(json[key].videoURL);
console.log(json[key].tabID);
console.log(json[key].videoURL);
}
}
/***************************************/
//alert(numKeys(obj))
//Object.prototype.foobie = 'bletch'; // add property to foo that won't be counted
var count = 0;
for (var k in json) {
if (json.hasOwnProperty(k)) {
++count;
//alert("Key is " + k + ", value is" +...