Find in object / array

function getKeyByValue(object, value) {
  return Object.keys(object).find(key => object[key] === value);
}


const map = {"first" : "1", "second" : "2"};
console.log(getKeyByValue(map,"2"));
// To find a specific object in an array of objects
myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
Deixe um comentário 0

Your email address will not be published. Required fields are marked *