JavaScript 101, check your console for errors, there are a few:
- extra
;
inside json - undefined
_pcost
which should be_cost
- unfinished/incorrect
for
loop:;
instead of,
inside for loops in JavaScript, + the iteration counter missing
var data = {
"products": [{
"p_id": 111,
"p_name": "p_one",
"p_cost": 100
}]
};
var results = "";
for (var i = 0; i < data.products.length; i++) {
var obj = data.products[i];
var _pid = obj.p_id;
var _pname = obj.p_name;
var _cost = obj.p_cost;
results = _pid + "." + _pname + "." + _cost + "<br>";
}
console.log(results)
1
solved Can someone tell me what wrong with my code? [closed]