1

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

2
  • does console.log(itemId === 'E2') evaluate to true? And are you absolutely sure nothing else is going on in your code? Commented Jul 6, 2011 at 3:33
  • @Andy no, it doesn't evaluate to true... What else can be the difference between two vars apart from type? It would all make sense if the first one console.log(itemId) was undefined or something other than 'E2' Commented Jul 6, 2011 at 3:43

2 Answers 2

1

Works for me in FF4: enter image description here

Are you sure you don't have a typo or something in your actual code?

Sign up to request clarification or add additional context in comments.

2 Comments

Yea thats exactly what I would expect to see. Not so for my code. Those lines are a direct copy paste from where I was attempting to debug.
Ah, 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
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.