Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2016, 05:39 AM
Registered User
 
Join Date: Jun 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default data.js:14 Uncaught TypeError: Cannot read property 'id' of undefined

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);
};
 
Old June 6th, 2019, 01:01 AM
Registered User
 
Join Date: Jun 2019
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 
Old June 6th, 2019, 05:13 AM
Registered User
 
Join Date: Jun 2019
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

x <= proOBJ.length ---> x < proOBJ.length





Similar Threads
Thread Thread Starter Forum Replies Last Post
debug; says: this property is read-only, now eypril SQL Language 1 March 3rd, 2010 04:10 PM
Ajax Cart update Undefined Property modelreject BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 1 March 16th, 2009 10:04 AM
Loading JS in the same id place..PLZ HELP nospirit Java Basics 0 December 27th, 2005 08:44 AM
Read a property file Sindhu EJB 0 December 1st, 2005 06:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.