Here is my JSON
[
{
"var5":"item-company-1",
"asd2":"item-company-1",
"tie1":"0",
"cxs1":"481.891px",
"xcve2":"130.563px"
},
{
"var5":"item-company-2",
"asd2":"item-company-2",
"tie1":"0",
"cxs1":"481.891px",
"xcve2":"130.563px"
},
{
"var5":"item-company-3",
"asd2":"item-company-3",
"tie1":"0",
"cxs1":"481.891px",
"xcve2":"130.563px"
}
]
How do I read the key and the value? Keep in mind I might not know the Key. I tried using...
var data = JSON.parse(json);
Object.keys(data).forEach(function(prop) {
// `prop` is the property name
// `data[prop]` is the property value
console.log(prop + " = " + data[prop]);
});
However it just outputs
0 = [object Object]
1 = [object Object]
2 = [object Object]
EDIT FOR CLARIFICATION
in PHP I get the following output which is what I'm trying to achieve from javascript
0:
var5 => item-company-1
asd2 => item-company-1
tie1 => 0
cxs1 => 481.891px
xcve2 => 130.563px
1:
var5 => item-company-2
asd2 => item-company-2
tie1 => 0
cxs1 => 481.891px
xcve2 => 130.563px
2:
var5 => item-company-3
asd2 => item-company-3
tie1 => 0
cxs1 => 481.891px
xcve2 => 130.563px
console.log(prop, " = ", data[prop])console.logwhen you want to output an object.console.log, so it would beconsole.log(prop, "=", data[prop])