Answers for "js find inside object"

3

find item in object js

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.
Posted by: Guest on May-10-2021
0

Find item from objects

// 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'));
Posted by: Guest on January-02-2022

Code answers related to "js find inside object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language