JSFiddle - React, Tailwind, and code Playground
JavaScript
function iterateObj(obj, callback){
if (obj == null || typeof obj != "object"){
return;
}
for (var key in obj){
// callback(key, obj[key]);
alert("obj.key--->" + obj.key);
alert("obj[key]--->" + obj[key]);
// callback(key, obj.key);
}
}
var sample = {
start: "bar",
notes: [{location: "somewhere"}, {time: "someday"}],
anotherobj: {
another: "1",
another1: "3",
another2: "2"
},
end: "foo"
}
iterateObj(sample, function(key, value){
// console.log("key: " + key+ ", " + "value: "+ value);
})