“Suchen Sie Elemente aus dem Objekt” Code-Antworten

Item in Objekt JS finden

const object1 = {
  a: {val: "aa"},
  b: {val: "bb"},
  c: {val: "cc"}
};

let a = Object.values(object1).find((obj) => {
	return obj.val == "bb"
});
console.log(a)
//Object { val: "bb" }
//Use this for finding an item inside an object.
Disgusted Dragonfly

Item aus Objekten finden

// Objects

let foods = {
  apples: 25,
  oranges: 32,
  plums: 28,
  bananas: 13,
  grapes: 35,
  strawberries: 27,
};

function checkInventory(scannedItem) {
  if (foods[scannedItem] != undefined) return foods[scannedItem];
  return foods;
}

console.log(checkInventory('apples'));
YosKa

Suchen Sie Elemente aus dem Objekt

// 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));
YosKa

Ähnliche Antworten wie “Suchen Sie Elemente aus dem Objekt”

Fragen ähnlich wie “Suchen Sie Elemente aus dem Objekt”

Weitere verwandte Antworten zu “Suchen Sie Elemente aus dem Objekt” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen