JSFiddle - React, Tailwind, and code Playground
by roberkules
JavaScript
var data = {"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}};
var result = [];
getNames(data, "name");
document.write("result: " + result.join(", "));
function getNames(obj, name) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
if ("object" == typeof(obj[key])) {
getNames(obj[key], name);
} else if (key == name) {
result.push(obj[key]);
}
}
}
}