I have an array members. This array has a name as the index (e.g. "John Smith") and an array with "degree" and "id", like so:
I have a search that fires on keyup action. It is supposed to search through the member names (the index) and then output the name of any matching members to the console:
function memberSearch(){
var $input = $("#guestsearch>input");
var val = $input.val();
console.log(val);
$.each(members, function(i,v){
if(i.indexOf(val)>-1){
console.log(members[i]);
}
})
}
However, this doesn't output anything except the search value val. Even if the $.each function is just console.log(i), nothing outputs.
If I manually type console.log(members) into console, the screenshot from above is the result.
members is populated by this segment of a function:
$.each(json.response.data[0].members, function(i,v){
var m = json.response.data[0].members[i];
var name = m.name;
if(name.typeof!=="undefined"&&name!=""&&name!=null&&name.length>0){
members[name] = [];
members[name]["degree"] = m.degree;
members[name]["id"] = m.id;
}
})
How can I make this search work?

var members = [];, then it is populated by another functionmembersis an Array? Seems like you're describing a plain Object. Where's the code? Are you trying to put non-index names on an Array? If so,$.eachwill ignore them.indexOf?