JavaScript Callback for find not working-Javascript

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)
Answer:1

You need to change every to some for first, because the every will always return false and also return the result of Object.keys(element).some.... And can simplify.

But I can suggest you more simple code, you only need to check if the property is in the object and it's value is the val, with using lambdas

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){
    return (element,index,array) => inputKey in element && element[inputKey] === val;
}

let res = objectsArray.find(mytestMatchesProp('a',9))
 console.log('output',res)
Answer:2

I have this [sample][1], what I want is to have this result[![enter image description here][2]][2] Note: a.) 1 and 2 will be connected while 3 will be produced in the third mousedown click. b.) 1,...

I have this [sample][1], what I want is to have this result[![enter image description here][2]][2] Note: a.) 1 and 2 will be connected while 3 will be produced in the third mousedown click. b.) 1,...

  1. make parallel lines in illustrator
  2. make parallel lines photoshop
  3. make parallel lines in autocad
  4. make parallel lines
  5. make parallel lines adobe illustrator
  6. make parallel lines in sketchup
  7. make lines parallel solidworks
  8. make lines parallel powerpoint
  9. inkscape make parallel lines
  10. make parallel curved lines
  11. how to make parallel lines with a compass
  12. how to make parallel lines using compass
  13. how to make parallel lines in construction
  14. how to make parallel lines with set squares
  15. how to make parallel lines on geogebra
  16. how to make parallel lines geometry
  17. how to make parallel lines on geometer's sketchpad
  18. make two lines parallel illustrator
  19. make two lines parallel in autocad
  20. how to make parallel lines on keyboard

I have this clock object: var Clock = { start: function () { $('#btnScrollPause').show(); $('#btnScrollResume').hide(); advance(); this.interval = setInterval(function () ...

I have this clock object: var Clock = { start: function () { $('#btnScrollPause').show(); $('#btnScrollResume').hide(); advance(); this.interval = setInterval(function () ...

  1. callback in this.setstate
  2. javascript callback with this
  3. typescript callback with this
  4. js callback with this
  5. callback function with this
  6. c++ callback with this
  7. jquery callback with this
  8. javascript pass callback with this
  9. javascript callback function with this
  10. typescript callback function with this

I'am studying React JS library, and i wish create a "loop" of component, returning array values from json file. Here my json file: { "data": { "children": [{ "data": { "score": 4 ...

I'am studying React JS library, and i wish create a "loop" of component, returning array values from json file. Here my json file: { "data": { "children": [{ "data": { "score": 4 ...

  1. loop component in react
  2. loop component in talend
  3. create react component with loop

I have the following django template and I have defined a button in it so that it calls the javascript function which I added to the page like below. I have the below issues: 1) If I bring the script ...

I have the following django template and I have defined a button in it so that it calls the javascript function which I added to the page like below. I have the below issues: 1) If I bring the script ...