the murmurous sea

JS ES5: filter 본문

#dev/개념정리

JS ES5: filter

lunacer 2020. 4. 29. 17:45

1. method
2. creates a new array filled with all array elements that pass a test (provided as a function).
3. does not execute the function for array elements without values.
4. does not change the original array.

 

[Syntax]

let newArray = arr.filter(callback(element[, index, [array]])[, thisArg])

callback

Required

A function to be run for each element in the array.
is a predicate, to test each element of the array.
Return true to keep the element, false otherwise.
function(element, index, array) element Required
The value of the current element being processed in the array.
index Optional
The array index of the current element being processed in the array.
array Optional
The array object the current element belongs to.
The array filter was called upon.
: why need this argument...?
thisArg Optional

A value to be passed to the function to use as its "this" value when executing callback.
If this parameter is empty, the value "undefined" will be passed as its "this" value

 

[Return value]

   : A new array containing all the array elements that pass the test.
   : If no elements pass the test, an empty array will be returned.


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

https://www.w3schools.com/jsref/jsref_filter.asp

'#dev > 개념정리' 카테고리의 다른 글

JS ES5: reduce()  (0) 2020.04.30
JS ES1: sort()  (0) 2020.04.30
JS ES5: forEach vs map  (0) 2020.04.29
Tree of nodes / DOM  (0) 2020.04.22
HTML5: data-  (0) 2020.04.17
Comments