In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you how es6 judges whether the array contains relevant knowledge points about objects. 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. Let's take a look at it.
Es6 method to determine whether the array contains objects: 1, using the find () method, this method returns the value of the first element of the providing function in the array, if there is no return undefined;2, using the findIndex () method, the method returns the index that satisfies the first element of the providing function in the array, if there is no return-1.
This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.
How does es6 determine whether an array contains objects?
Es6 determines that an object already exists in the array.
The find () method returns the value of the first element in the array that satisfies the provided test function. Otherwise, undefined is returned.
The findIndex () method returns the index of the first element in the array that satisfies the provided test function. Otherwise,-1 is returned.
Examples are as follows:
Find method:
Var objArr = [{id:1, name:'jiankian'}, {id:23, name:'anan'}, {id:188, name:'superme'}, {id:233, name:'jobs'}, {id:288, name:'bill', age:89}, {id:333}]; var ret2 = objArr.find ((v) = > {return v.id = = 233;}); console.log (ret2); / / return {id:233, name:'jobs'}
/ / when undefined is returned, it means it is not in objArr and can be added.
FindIndex method:
Var objArr = [{id:1, name:'jiankian'}, {id:23, name:'anan'}, {id:188, name:'superme'}, {id:233, name:'jobs'}, {id:288, name:'bill', age:89}, {id:333}]; var ret2 = objArr.findIndex ((v) = > {return v.id = = 233;}); console.log (ret2); / / return 3
/ / when-1 is returned, it means that it is not in objArr and can be added.
These are all the contents of the article "how es6 determines whether an array contains objects or not. 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.