当前位置:网站首页>Usage of some, every, find, FindIndex
Usage of some, every, find, FindIndex
2022-07-23 11:32:00 【Superman can't fly~~】
some、every、find、findIndex、reduce Usage of
Preface
From the beginning for Loop traversal method , Later, various traversal methods emerged in endlessly , In fact, the biggest difference is the application scenario . What we need to remember most is , Under what circumstances, which method is more appropriate ..
Array data
var potatos = [{
id: '1001', weight: 50 },
{
id: '1002', weight: 80 },
{
id: '1003', weight: 120 },
{
id: '1004', weight: 40 },
{
id: '1005', weight: 110 },
{
id: '1006', weight: 60 }]
Tips : The following is the main body of this article , The following cases can be used for reference
some
var hasbig = potatos.some(potato => {
return potato.weight > 100 })
//true
our some fellow , Just find a qualified , Just come back and report true So it won't be all traversed , Don't do extra work ( Excellent performance ), The return result is Boolean .
every
var allbig = potatos.every(potato => {
return potato.weight > 100 })
//false
Traverse each element , If any element fails to meet the condition, it will return false, If the element that does not meet the condition is not found after traversal , Then all meet the conditions , return true
find
var big = potatos.find(potato => {
return potato.weight > 100 })
//{ id: '1003', weight: 120 }
find and some Is very similar , Are looking for qualified , One can however some I went in for a search and came back to report “ Yes ”(true), and find Then return the whole data ( Returns the first qualified object )
findIndex
var i = potatos.findIndex(potato=>{
return potato.weight > 100 })
//2
find Twin brother , however find What is returned is data , and find The index value of the main sentence is returned
summary
Traversal data , Query the data that meets the conditions , But it's confusing
In this paper, the reference :https://juejin.cn/post/6844903870154588168
边栏推荐
- TypeScript 高级类型
- Php+ code cloud code hook automatically updates online code
- C语言之二分查找法或折半查找法剖析(经典例题,经典解析)
- 文件上传漏洞常见绕过方式
- Nepctf 2022 misc < check in question > (extreme doll)
- [C language] what is a function? Classification and emphasis of functions (help you quickly classify and remember functions)
- JS higher order function
- Application of higher-order functions: handwritten promise source code (III)
- 数字藏品开发/数字藏品系统开发解决方案
- Last child does not take effect
猜你喜欢
随机推荐
Some operations of composer
Constructor, prototype chain, instanceof
Dynamically set the theme color of the card
C语言调试常见错误——简答
文件上传漏洞原理
XML建模
How to customize JSP Tags
印尼央行行长称该国正在积极探索加密资产
美联储布拉德:上周就业报告表明美国经济稳健,可以承受更高的利率
First blog
Resizeobserver ignoring buried point records - loop limit exceeded
SQL labs 5-6 customs clearance notes
第一篇博客
Basis of penetration test
TypeScript 高级类型
Two sorting and one random data fetching of stored procedures
Rogue goto statements in C language
【C语言】什么是函数?函数的分类和侧重(帮你快速分类和记忆函数)
Common bypass methods for file upload vulnerabilities
slice()和splice()区别









