xxxxxxxxxx
const filteredArray = array.filter(element => element.id != id))
xxxxxxxxxx
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length < 6);
console.log(result);
//OUTPUT: ['spray', 'limit', 'elite']
xxxxxxxxxx
var numbers = [1, 3, 6, 8, 11];
var lucky = numbers.filter(function(number) {
return number > 7;
});
// [ 8, 11 ]
xxxxxxxxxx
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 5)
console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
array filter
xxxxxxxxxx
let arr = [1,2,3,0,4,5]
let arr2=[0,2]
let ans = arr.filter(function(value,index,array){
return !this.includes(value)
},arr2)
console.log(ans)
xxxxxxxxxx
const grades = [10, 2, 21, 35, 50, -10, 0, 1];
// get all grades > 20
const result = grades.filter(grade => grade > 20); // [21, 35, 50];
// get all grades > 30
grades.filter(grade => grade > 30); // [35, 50]
xxxxxxxxxx
const arr = ['pine', 'apple', 'pineapple', 'ball', 'roll'];
const longWords = arr.filter(item => item.length > 5);
console.log(longWords); // ['pineapple']
xxxxxxxxxx
// filter(): returns a new array with all elements that pass the test
// If no elements pass the test, an empty array will be returned.
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
xxxxxxxxxx
var id = 2;
var list = [{
Id: 1,
Name: 'a'
}, {
Id: 2,
Name: 'b'
}, {
Id: 3,
Name: 'c'
}];
var lists = list.filter(x => {
return x.Id != id;
})
console.log(lists);
xxxxxxxxxx
var jsonarr = [
{
id: 1,
name: "joe"
},
{
id: -19,
name: "john"
},
{
id: 20,
name: "james"
},
{
id: 25,
name: "jack"
},
{
id: -10,
name: "joseph"
},
{
id: "not a number",
name: "jimmy"
},
{
id: null,
name: "jeff"
},
]
var result = jsonarr.filter(user => user.id > 0);
console.log(result);