Hello programmers,
can somebody please help me out here ? what could be the cause of this error message:
Uncaught TypeError: Cannot read property 'id' of undefined
here is the code
Code:
var products = [
{"id": 1, "name": 'Assassin Creed', "category": '', "price": 13.45, "quantity_in_stock": 5},
{"id": 2, "name": 'Thunder', "category": '', "price": 15.45, "quantity_in_stock": 5},
{"id": 3, "name": 'The Witcher', "category": '', "price": 18.45, "quantity_in_stock": 5},
{"id": 4, "name": 'Red Hair', "category": '', "price": 21.45, "quantity_in_stock": 5},
{"id": 5, "name": 'The brothers', "category": '', "price": 23.45, "quantity_in_stock": 5}
];
localStorage.products = JSON.stringify(products);
var proOBJ = JSON.parse(localStorage.products);
var productlist = document.getElementById("productList");
for (x = 0 ; x <= proOBJ.length ; x++) {
var items = document.createElement("li");
items.id = "product" + proOBJ[x].id ;
items.classname = "product"+ proOBJ[x].id ;
items.appendChild(document.createTextNode(proOBJ[x].name));
productlist.appendChild(items);
};