Answers for "how to find an object by id"

3

js get object by id from array

myArray.find(x => x.id === '45');
Posted by: Guest on February-05-2021
0

Find items from object

// We've created an object, users, with some users in it and a function
// isEveryoneHere, which we pass the users object to as an argument.
// Finish writing this function so that it returns true only if the
// users object contains all four names, Alan, Jeff, Sarah, and Ryan, as keys, and false otherwise.

let users = {
  Alan: {
    age: 27,
    online: true,
  },
  Jeff: {
    age: 32,
    online: true,
  },
  Sarah: {
    age: 48,
    online: true,
  },
  Ryan: {
    age: 19,
    online: true,
  },
};

function isEveryoneHere(obj) {
  return ['Alan', 'Jeff', 'Sarah', 'Ryan'].every((name) =>
    obj.hasOwnProperty(name)
  );
}
console.log(isEveryoneHere(users));
Posted by: Guest on January-02-2022

Code answers related to "how to find an object by id"

Code answers related to "Javascript"

Browse Popular Code Answers by Language