Reputation: 2185
This is driving me insane. I am trying to grab an object in javascript using a dynamic variable. Static variables appear to work, yet I cant for the life of me see the difference between the static vars I put in and the dynamic vars.
My snippet below better illustrates the issue
console.log(itemId); //E2
console.log(typeof itemId); //string
console.log(typeof 'E2'); //string
console.log(ganttObject.items['E2']); //object [with data]
console.log(ganttObject.items[itemId]); //undefined
The weird thing is that I have extensively used dynamic calling of objects elsewhere in the script, but it is breaking here.
Tested in Safari & Chrome
Upvotes: 1
Views: 474
Reputation: 2185
I found the answer at last by tracing the value of itemId
to the source. Turns out an edit in the html generation added a space after my id.
Moral of the story:
Remember that trailing spaces won't show up on the console window
Upvotes: 0
Reputation: 76218
Works for me in FF4:
Are you sure you don't have a typo or something in your actual code?
Upvotes: 1