/    Sign up×
Community /Pin to ProfileBookmark

getting value from object

This is an odd problem, i have an object (demQuestions), here is a dump of it (cut to 2 for simplicity):

[CODE]
Object {
0: Object {
question_short: “Number of beds”
op1: “Less than 50”
op2: “50 to 99”
op3: “100 to 299”
op4: “300 to 499”
op5: “500 or more”
}
1: Object {
question_short: “Type of service”
op1: “General medical and surgical”
op2: “Specialty: psychiatric”
op3: “Specialty: rehabilitation”
op4: “Specialty: pediatric”
op5: “Specialty: oncology”
op6: “Other (please specify)”
}
} [/CODE]

i need to get the “0” -> “question_short” value, but cant figure out how?

demQuestions.0.question_short = error (missing ; before statement)
eval (‘demQuestions.0.question_short’) = error (missing ; before statement)

i have been using this object alot but normaly i get the values using $.each(), so it cycles through 0,1,2,3,4… itself. how can i access the values directly without going through the $.each

seems like such a stupid problem but im far from an expert when it comes to JS object’s, im 99% sure the problem is the fully numeric “key” being used.

Thanks,
-aPeg

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@NedalsMar 24.2010 — Add some '='s and a few commas

And you don't need the inner 'Object'

<i>
</i>Object = {
0: {
question_short: "Number of beds",
op1: "Less than 50",
op2: "50 to 99",
op3: "100 to 299",
op4: "300 to 499",
op5: "500 or more"
},
1: {
question_short: "Type of service",
op1: "General medical and surgical",
op2: "Specialty: psychiatric",
op3: "Specialty: rehabilitation",
op4: "Specialty: pediatric",
op5: "Specialty: oncology",
op6: "Other (please specify)"
}
}
alert(Object[0]['question_short'])
×

Success!

Help @apeg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...