I'm on a mission to determine whether a specified key exists in an array of objects. If the key value is present, I need to return true; otherwise, false.
I enter the key into a text box as input and then attempt to check if it exists in the array of objects, but so far, no luck.
Here's what I've attempted:
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 input 'the carribean
', which does exist in the object array, it still displays 'does not exist' in the console output.
How can I troubleshoot and fix this issue?