Wednesday, 14 August 2013

console.log shows correct output but with error messages

console.log shows correct output but with error messages

I had a chrome extension that was running just fine. But when I
resurrected it, it is showing a collection of errors.
var wordObject = [
{ word: 'peanut', definition:'The oval seed of a South American
plant...' }
, { word: 'piano', definition:'A large keyboard musical instrument
wi...' }
, { word: 'cigarette', definition:'A thin cylinder of finely cut
tobacco...' }
];
console output
console.log(wordObject.length);
console.log(wordObject[0].word);
The console.log in fact returns the number objects in the array and the
'word' property value of the first object, But It also shows the below
errors.
Uncaught TypeError: Cannot read property 'length' of undefined
Uncaught TypeError: Cannot read property '0' of undefined
So the problem is that even though console.log shows the correct output, I
cannot use this code since the above errors are shown too ?

No comments:

Post a Comment