xxxxxxxxxx
const arrayOfObjects = [
{ name: 'John', age: 30, city: 'New York' },
{ name: 'Alice', age: 25, city: 'Los Angeles' },
{ name: 'Bob', age: 35, city: 'San Francisco' }
];
// Extracting specific keys and values
const result = arrayOfObjects.map(({ name, city }) => ({ name, city }));
console.log(result);
[ { name: 'John', city: 'New York' }, { name: 'Alice', city: 'Los Angeles' }, { name: 'Bob', city: 'San Francisco' }]
xxxxxxxxxx
var array = [
{ name:"string 1", value:"this", other: "that" },
{ name:"string 2", value:"this", other: "that" }
];
var foundValue = array.filter(obj=>obj.name==='string 1');
console.log(foundValue);
xxxxxxxxxx
let users = [
{
name: 'John',
age: 20,
},
{
name: 'Richard',
age: 25,
}
];
let names = users.map(user => user.name);
// ['John', 'Richard]
xxxxxxxxxx
const search = what => array.find(element => element.name === what);
xxxxxxxxxx
let itemYouWant = null;
array.forEach((item) => {
if (item.name === 'string 1') {
itemYouWant = item;
}
});
console.log(itemYouWant);