Answers for "check if key exists in array of objects javascript"

3

javascript check if value exists in array of objects

var arr = [{ id: 1, name: 'JOHN' }, 
  { id: 2, name: 'JENNIE'}, 
  { id: 3, name: 'JENNAH' }];

function userExists(name) {
  return arr.some(function(el) {
    return el.name === name;
  }); 
}

console.log(userExists('JOHN')); // true
console.log(userExists('JUMBO')); // false
Posted by: Guest on January-09-2021
0

object keys includes some key

var keyExistsOn = (o, k) => k.split(".").reduce((a, c) => a.hasOwnProperty(c) ? a[c] || 1 : false, Object.assign({}, o)) === false ? false : true;
Posted by: Guest on February-04-2021
-1

js check if object key exists

var obj = { key: undefined };
obj["key"] !== undefined // false, but the key exists!
Posted by: Guest on July-23-2020

Code answers related to "check if key exists in array of objects javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language