1var filter = {
2 address: 'England',
3 name: 'Mark'
4};
5var users = [{
6 name: 'John',
7 email: 'johnson@mail.com',
8 age: 25,
9 address: 'USA'
10 },
11 {
12 name: 'Tom',
13 email: 'tom@mail.com',
14 age: 35,
15 address: 'England'
16 },
17 {
18 name: 'Mark',
19 email: 'mark@mail.com',
20 age: 28,
21 address: 'England'
22 }
23];
24
25
26users= users.filter(function(item) {
27 for (var key in filter) {
28 if (item[key] === undefined || item[key] != filter[key])
29 return false;
30 }
31 return true;
32});
33
34console.log(users)
1// use .filter and write multiple validations in the callback function
2
3let numbers = [3, 7, 2, 15, 4, 9, 21, 14];
4
5let filteredNumbers = numbers.filter(function (currentElement) {
6 if (currentElement > 3 && currentElement < 17) {
7 return true;
8 }
9});
10
11console.log(filteredNumbers);