I have written a custom callback function for Javascript's find function
but that is always yielding undefined
var objectsArray = [
{ 'a': 1, 'b': 2, 'c': 3 },
{ 'a': 41, 'b': 5, 'c': 7 },
{ 'a': 9, 'b': 2, 'c': 3 },
{ 'a': 4, 'b': 5, 'c': 99 }
];
function mytestMatchesProp(inputKey,val){
let matchFunc = function(element,index,array){
Object.keys(element).every(function(key){
let val1 = (key==inputKey) && (element[key] == val)
return val1
})
}
return matchFunc
}
let res = objectsArray.find(mytestMatchesProp('a',9))
console.log('output',res)
I have added a running snippet, any suggestion would be helpful. Maybe i am missing something minor