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 differences between filter and map in es6

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

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor will share with you what are the relevant knowledge points about the difference between filter and map in es6. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

The difference between filter and map in es6: the new array returned by the map method is the mapping of the original array, and the length of the new array is the same as the original array, but the value is different; while the new array returned by the filter method is filtered by the original array, and the length of the new array is different from the original array, and the value remains the same.

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

What is the difference between filter and map in es6

Map and filter parameters are exactly the same

Array.filter (function (currentValue,index,arr), thisValue)

CurrentValue: array elements

Index: index

Arr: primitive array

ThisValue: used as the callback for this execution, passed to the function, used as the value of "this"

Different uses:

1. The new array returned by the map method is the mapping of the original array. What is the mapping? That is, the length of the original array is the same, and the value is processed accordingly.

2. The value returned by the filter method is the new array after filtering the original array, which is different from the length of the original array, and the value remains the same.

Examples are as follows:

Filter:

Syntax:

Arr.filter (function (val,index,arr) {})

As a result, it can be concluded that:

Filter removes all data that is fake, in other words, filtering, filtering out data that meets the criteria.

Map:

Syntax:

Arr.map (function (val,index,arr) {})

Implement it with the same code and see what the result is.

Therefore, map is generally suitable for calculation and can return the calculation result.

However, when a condition is encountered, it will only return whether it is ture or false.

These are all the contents of the article "what's the difference between filter and map in es6". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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