let newArray = arr.filter(callback(currentValue[, index, [array]]) {}[, thisArg]);
let numbers = [1, 4, 9] let parameters = numbers.filter((num, index, arr) => {console.log(num, index, arr)})
- 값은
1 0 [ 1, 4, 9 ]
4 1 [ 1, 4, 9 ]
9 2 [ 1, 4, 9 ]
var ss = [ {name : 'apple, price : 2000}, {name : 'banana', price : 1200}, {name : 'melon', price : 3000} ]; var newFilter = ss.filter((e) => e.price >= 2000); console.log(newFilter);
-> 값은 {name : 'apple, price : 2000},
{name : 'banana', price : 1200}
var A = [ {name : "이건", salary : 5000}, {name : "홍길동", salary : 1000}, {name : "임신구", salary : 3000}, {name : "이승룡", salary : 2000} ]; var B = A.filter(function(e){ return e.name == "이건"; });
-> 값은 {name : "이건", salary : 5000}
var A = [ {name : "이건", salary : 5000}, {name : "홍길동", salary : 1000}, {name : "임신구", salary : 3000}, {name : "이승룡", salary : 2000} ]; var B = A.filter((e) => e.name == "이건"); console.log(B);
-> 값은 {name : "이건", salary : 5000}
function a(value) { return value >= 10; }; var b = [12, 5, 7, 33, 50].filter(a); console.log(b)
-> 값은 [12, 33, 50]
let kk = [ {name : 'banana', price : 3000}, {name : 'apple', price : 2000}, {name : 'melon', price : 10000} ]; function findnames(names) { return names.name === 'banana'; } console.log(kk.find(findnames));
let kk = [ {name : 'banana', price : 3000}, {name : 'apple', price : 2000}, {name : 'melon', price : 10000} ]; let result = kk.find(i => i.name === 'banana'); console.log(result);
-> i는 어떠한 것으로 바꿔도 상관없음
let kk = [ {name : 'banana', price : 3000}, {name : 'apple', price : 2000}, {name : 'melon', price : 10000} ]; let index = kk.findIndex(findtitle => findtitle.name == 'apple'); console.log(index);
-> 값은 1