“JavaScript filter array beberapa nilai” Kode Jawaban

filter array javascript dengan beberapa id

let itemsids = [1,45,7.4]
const result = data.items.filter((e) => itemsids.includes(e.id))
Aashiq Hasnat

JavaScript filter array beberapa nilai

// 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);
Wicked Wryneck

JavaScript filter array beberapa kondisi

var filter = {
  address: 'England',
  name: 'Mark'
};
var users = [{
    name: 'John',
    email: '[email protected]',
    age: 25,
    address: 'USA'
  },
  {
    name: 'Tom',
    email: '[email protected]',
    age: 35,
    address: 'England'
  },
  {
    name: 'Mark',
    email: '[email protected]',
    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)
Xenophobic Xenomorph

Jawaban yang mirip dengan “JavaScript filter array beberapa nilai”

Pertanyaan yang mirip dengan “JavaScript filter array beberapa nilai”

Lebih banyak jawaban terkait untuk “JavaScript filter array beberapa nilai” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya