In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge about "how JavaScript finds prime numbers in arrays". In the actual operation process of cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Operating environment of this tutorial: Windows 7 system, Javascript version 1.8.5, Dell G3 computer.
What are prime numbers?
Prime numbers, also known as prime numbers, refer to natural numbers greater than 1 that have no other factors except 1 and itself.
JavaScript How to find prime numbers in an array
Use the for loop statement or filter() method to loop through the array, in each loop to determine whether an array element is prime, if yes, then output the element.
The method of determining whether it is a prime number is to divide a number by 2 to sqrt(this number). If it can be divided exactly, it indicates that the number is not a prime number, and vice versa.
Here's how to do it:
Using the for loop
var a = [31,33,35,37,39,41,43,45,57,49,51,53];for(var i=0;i
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.