Example 1: who to accses to an object vallue inside an array with .filter method js
const array = [
{
username: "john",
team: "red",
score: 5,
items: ["ball", "book", "pen"]
},
{
username: "becky",
team: "blue",
score: 10,
items: ["tape", "backpack", "pen"]
},
{
username: "susy",
team: "red",
score: 55,
items: ["ball", "eraser", "pen"]
},
{
username: "tyson",
team: "green",
score: 1,
items: ["book", "pen"]
},
];
const filterArray=array.filter(word=>word.team==="red")
Example 2: filter javascript array
var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
Example 3: javascript filter array of objects
function isBigEnough(value) {
return value >= 10
}
let filtered = [12, 5, 8, 130, 44].filter(isBigEnough)
Example 4: JavaScript Array Methods .filter()
const colours = ['green', 'black', 'dark-orange', 'light-yellow', 'azure'];
const result = colours.filter(colour => colour.length > 6);
console.log(result);
Example 5: filter array js
const arr = ['pine', 'apple', 'pineapple', 'ball', 'roll'];
const longWords = arr.filter(item => item.length > 5);
console.log(longWords);