0

this might sound dumb but I am trying to display the value of content: I do console.log(teams); I open firebug on mozilla and here is what I get :

 [Object { id= "50",  content= "Team 1 test" ,  date="Tue Mar 26 2013 12:00:00"}]

when I do alert(teams.content); or alert(teams[content]); it returns object undefined.What am I doing wrong please ?

3 Answers 3

3

The object is wrapped in an array (notice the [ and ])

teams[0].content;
Sign up to request clarification or add additional context in comments.

8 Comments

console.log(teams[0]); this returns : Object { id= "50" , content= "Team Pro-Motion test" , date= "Tue Mar 26 2013 12:00:00" }
but if I add the .content, it says undefined again
@fogsy add .content to what?
to teams[0] ... so when I do console.log(teams[0].content); its undefined.
@fogsy can you show us an example on jsfiddle.net or your actual site?
|
3

Its not just object, but an array of objects, . Your object is at 0th index of array.

So try this,

alert(teams[0].content)


Also, alert(teams[content]); is a wrong way. The index should be a string here.

So, another way would be,

alert(teams[0]['content']);

4 Comments

TypeError: eventsOfDay[0] is undefined [Break On This Error] console.log(eventsOfDay[0]['content']);
you said teams. not eventsOfDay!
yes but its the same. just the variable name that is different.
@fogsy, I guess you can remove your comments now as you have find out that error is caused by something else.
1

Teams is an array.

To read a value you need to index it

teams[index].content

2 Comments

on here it asys index is not defined.
I didnt mean to say use index per se.. but a variable that indexes into the array.. for example if var size = teams.length; now you can use teams[x].content to access the xth element of the array. where 0<= x < size

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.