Answers for "objec key found js"

7

how to find the key of an value in an object

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


const map = {"first" : "1", "second" : "2"};
console.log(getKeyByValue(map,"2"));
Posted by: Guest on August-07-2020
1

obj[key].includes is not a function

// Try using Object.values instead:

var aa = [{id: 1,type: 1,status: 1,name: 'txt'},{id: 2,type: 1,status: 1,name: 'txt'},{id: 3,type: 0,status: 0,name: 'txt'}];

function filterIt(arr, searchKey) {
  return arr.filter(function(obj) {
    return Object.values(obj).includes(searchKey);
  });
}

console.log(filterIt(aa, 'txt'));
Posted by: Guest on December-15-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language