I am trying to find out if the given key exists in array of object. if the value key exists then i want to return true else false.
i giving input of key from text box and then checking if the key exists in array of objects, but i couldn't get it.
here is what i have tried
code:
var obj = [{
"7364234":"hsjd",
"tom and jerry":"dsjdas",
"mickey mouse":"kfjskdsad",
"popeye the sailor man":"alkdsajd",
"the carribean":"kasjdsjad"
}]
var val = $("input[name='type_ahead_input']").val();
if (obj[val]) {
console.log('exists');
} else {
console.log('does not exist');
}
if i give input as 'the carribean
' which exists in array of object, even then its outputting in console as does not exist.
how can i resolve this?