Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript filter array multiple conditions

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)
Comment

javascript filter array multiple values

// 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);
Comment

array filter with multiple conditions

var conditions = [];

 // Dynamically build the list of conditions
 if(startDateFilter) {
    conditions.push(function(item) { 
       return item.transdate >= startDateFilter.startDate;
    });
 };

 if(categoryFilter) {
     conditions.push(function(item) {
         return item.cateogry === categoryFilter.category;
     });
 };
 // etc etc
Comment

PREVIOUS NEXT
Code Example
Javascript :: js array to string 
Javascript :: reverse json.stringify 
Javascript :: create dynamic element in javascript 
Javascript :: import js file 
Javascript :: website implement jquery in js 
Javascript :: angular 6 key value pair getvalue example 
Javascript :: javascript add event listenner for multiple events 
Javascript :: how to write a json in r 
Javascript :: delete in javascript 
Javascript :: reload page after form submit javascript 
Javascript :: secure random nodejs 
Javascript :: foreach 
Javascript :: rock paper scissors js 
Javascript :: js delete json element 
Javascript :: javascript alert 
Javascript :: lodash sort json 
Javascript :: nodejs download file 
Javascript :: jquery timepicker 
Javascript :: javascript split remove last element 
Javascript :: Configure the Chrome debugger react 
Javascript :: sequelize update sql 
Javascript :: node get value from map 
Javascript :: unshift method in javascript 
Javascript :: my vscode does not recognize react code syntax 
Javascript :: usecallback hook react 
Javascript :: react hooks vs redux 
Javascript :: how to use platform.select 
Javascript :: the sum of all first n natural numbers js 
Javascript :: for javascript 
Javascript :: farewell discord.js 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =