How to find an object with a specific value in a JavaScript object array?

I have an array structured like this:

dataArray = [{‘key’:‘73’,‘value’:‘example’},{‘key’:‘45’,‘value’:‘example’}, …]

Although I cannot modify the array’s format, I have been provided with a key value of 45. I need to retrieve the corresponding ‘example’ associated with that key from the array. What would be the best way to accomplish this in JavaScript or jQuery?

You can use JavaScript’s find() method to get the object with the key 45, and then access its value:

const dataArray = [{'key':'73','value':'example'},{'key':'45','value':'example'}];
const found = dataArray.find(item => item.key === '45');
const value = found ? found.value : null;
console.log(value); // Output: 'example'