In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how JS array judges whether the elements meet the given conditions, has a certain reference value, interested friends can refer to, I hope you have a lot of gains after reading this article, let Xiaobian take you to understand.
1. Use the for statement to traverse the array and check whether the elements in the array are even.
var a = [2,4,5,6,8],b=0;for(var i=0;i if (a[i] % 2 != 0) { b=0 break; }else{ b++; }}if (b) { console.log("all even");} else { console.log("not all even");}
Using some() methods, you can detect whether there are elements in the array that meet the conditions.
Thinking differently, it can also be used to check whether all elements in the array do not meet the specified conditions. If they do not meet the specified conditions, it will return false, and if one or more match, it will return true.
function f(value, index, ar) { if (value % 2 != 0) { return true; }}var a = [2,4,6,8,10,12];var b = a.some(f);if (b) { console.log("not all even");} else { console.log("all even numbers");} Thank you for reading this article carefully. I hope that the article "How JS Array Determines whether an Element satisfies a given condition" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support it a lot. Pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!
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.