Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the parameters of the es6 filter method

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the parameters of the es6 filter method". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the parameters of the es6 filter method".

The filter method accepts two parameters: 1, a callback function, which cannot be omitted, and is used to set conditions to filter array elements and return elements in the array that meet the conditions, syntax "function (current value, current index, array object) {.}"; 2, an optional parameter for the object for which the this keyword can be used in the callback function.

The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.

The filter () method creates a new array, and the elements in the new array are checked for all eligible elements in the specified array.

To put it simply: the filter () method returns elements in the array that meet the specified criteria.

The filter () method accepts two parameters:

Array.filter (callbackfn [, thisArg])

Callbackfn: callback function, which cannot be omitted. It is used to set conditions to filter array elements. A maximum of 3 parameters are accepted. Syntax:

Function (currentValue, index,arr)

For each element in the array, the filter method calls the callbackfn function once.

CurrentValue must. Value of the current element

Index is optional. The index value of the current element

Arr is optional. The array object to which the current element belongs

ThisArg: optional parameter for the object for which the this keyword is used in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

The return value is a new array containing all the worthwhile true returned by the callback function. If the callback function returns false for all elements of array, the length of the new array is 0.

For each element in the array, the filter method calls the callbackfn function once (in ascending indexing order). The callback function is not called for missing elements in the array. The callback function is used in the same way as map.

Except for array objects, the filter method can be used by any object that has a length property and has a numerically indexed property name.

Example 1: filter out primes in an array

Var a = [31 value, 33 index, ar) {high = Math.floor (Math.sqrt (value)) + 1; for (var div = 2; div = this.min & value)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report