“JavaScript filter array beberapa kondisi” Kode Jawaban

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 kondisi”

Pertanyaan yang mirip dengan “JavaScript filter array beberapa kondisi”

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

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya