So I have an object. And what I want to do is search within the object for an ID and return it's fellow elements. What is my best course of action for something like this?
Looping through the object and checking each ID?
var questions = [
{
id : 'citizenship-1',
category : 'citizenship',
label : 'Are you an American Citizen?',
options : ['Yes','No'],
forceAnswer : false
},
{
id : 'citizenship-2',
category : 'citizenship',
label : 'Do you live in the United States?',
options : ['Yes','No'],
forceAnswer : false
}
];
So what I want to do is tell my javascript function to search for citizenship-2 in var questions and return the id, category, label, etc.
{
id : 'citizenship-2',
category : 'citizenship',
label : 'Do you live in the United States?',
options : ['Yes','No'],
forceAnswer : false
}
I'm primarily using javascript but also have jQuery available, if there is a better solution within.