xxxxxxxxxx
const found = accesses.find(x => x.Resource === 'Clients');
console.log(found)
xxxxxxxxxx
// app.js
const fruits = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];
const getFruit = fruits.find(fruit => fruit.name === 'apples');
console.log(getFruit);
javascript find array of objects
xxxxxxxxxx
let arr = [
{ name:"string 1", value:"this", other: "that" },
{ name:"string 2", value:"this", other: "that" }
];
let obj = arr.find(o => o.name === 'string 1');
console.log(obj);
xxxxxxxxxx
function getByValue2(arr, value) {
var result = arr.filter(function(o){return o.b == value;} );
return result? result[0] : null; // or undefined
}
xxxxxxxxxx
const filteredList = stories.filter(story => story.title.toLocaleLowerCase().includes(searchTerm.toLocaleLowerCase()));
xxxxxxxxxx
// 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));