Array.Filter Flashcards
let results = arr.filter(function(____ , ______ , ________) {
});
element, index, array
var words = [‘spray’, ‘limit’, ‘elite’, ‘exuberant’, ‘destruction’, ‘present’];
const result = words.filter(word => word.length > 6);
console.log(result); // expected output:
Array [“exuberant”, “destruction”, “present”]
Using the filter method on the years array, return an array of only the years in the twentieth century (remember: the twentieth century includes the year “2000”).
const years = [1989, 2015, 2000, 1999, 2013, 1973, 2012]; let century20;
century20 = years.filter( year => year >= 2000 );
console.log(century20);
what 3 elements of .Filter() are optional?
indexOptional
arrayOptional
thisArgOptional
function isBigEnough(value) { return value >= 10; }
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough); // filtered is
[12, 130, 44]
function isBigEnough // code
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough); // filtered is [12, 130, 44]
(value) {
return value >= 10;
}
var arr = [1,2,true,4,{"abc":123},6,7,{"def":456},9,[10]] var res = \_\_\_\_\_\_\_\_\_\_ // [1, 2, true, 4, 6, 7, 9, Array[1]]
arr.filter(Number);
console.log(1 == true);
true
console.log(1 === true);
false
var words = [‘spray’, ‘limit’, ‘elite’, ‘exuberant’, ‘destruction’, ‘present’];
const result = words.filter// return a word greater than 6 characters
console.log(result); // expected output: Array ["exuberant", "destruction", "present"]
(word => word.length > 6);
const userNames =['Steve', 'mike', 'Same']; const user = userNames
//filter names with S
(name=> name.charAt(0) === “s”)