181105 TIL array filter & HanTang skype 회의
array 메서드
filter (MDN)
definition:
array.filter = The filter() method creates a new array with all elements that pass the test implemented by the provided function.
syntax:
var newArray = arr.filter(callback(element[, index[, array]])[, thisArg])
description:
-
filter() calls a provided callback function once for each element in an array, and constructs a new array of all the values for which callback returns a value that coerces to true.
-
callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values.
-
Array elements which do not pass the callback test are simply skipped, and are not included in the new array.
-
callback is invoked which three arguments: 1) the value of the elements 2) the index of the element 3) the Array object being traversed
-
if a [thisArg] parameter is provided to filter, it will be used as the callback’s [this] value. Otherwise, the value [undefined] will be used as its [this] value. the [this] value ultimately observable by callback is determined according to the usual rules for determining the [this] seen by a function. <- 마지막 문장 이해가 잘 안감..
-
filter() does not mutate the array on which it is called. <- 확실히 이해 안감
-
the range of elements processed by filter() is set before the first invocation of callback. Elements which are appended to the array after the call to filter() begins will not be visited by callback.
-
if existing elements of the array are changed, or deleted, their value as passed to callback will be the value at the time filter() visits them; elements that are deleted are not visited.