фильтр массива JavaScript с несколькими идентификаторами
let itemsids = [1,45,7.4]
const result = data.items.filter((e) => itemsids.includes(e.id))
Aashiq Hasnat
let itemsids = [1,45,7.4]
const result = data.items.filter((e) => itemsids.includes(e.id))
// use .filter and write multiple validations in the callback function
let numbers = [3, 7, 2, 15, 4, 9, 21, 14];
let filteredNumbers = numbers.filter(function (currentElement) {
if (currentElement > 3 && currentElement < 17) {
return true;
}
});
console.log(filteredNumbers);
var filter = {
address: 'England',
name: 'Mark'
};
var users = [{
name: 'John',
email: 'johnson@mail.com',
age: 25,
address: 'USA'
},
{
name: 'Tom',
email: 'tom@mail.com',
age: 35,
address: 'England'
},
{
name: 'Mark',
email: 'mark@mail.com',
age: 28,
address: 'England'
}
];
users= users.filter(function(item) {
for (var key in filter) {
if (item[key] === undefined || item[key] != filter[key])
return false;
}
return true;
});
console.log(users)