In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you javascript how to determine whether the string is all 0, I believe most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Method: 1, use split () to convert the string into a character array, one character corresponds to an array element; 2, use every () to detect whether the elements in the character array are all 0, and if all are 0, it will return true, the syntax "arr.every (function f (v) {return vault 0;})".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
In javascript, to detect whether the characters in a string are all zeros, you can use the every () function of the array.
Use the split () function to convert a string into an array of characters, each character corresponding to an array element.
Use the every () function to detect whether the character elements in the character array are all 0, return "true" if all are 0, and return "false" if one is not 0.
Implementation code:
Function f (value) {return value = = 0;} var str= "00000"; var arr=str.split (''); if (arr.every (f)) {console.log ("all 0");} else {console.log ("not all 0");}
Function f (value) {return value = = 0;} var str= "00100"; var arr=str.split (''); if (arr.every (f)) {console.log ("all 0");} else {console.log ("not all 0");}
Description:
The every () method is used to determine whether all elements of the array meet the specified conditions.
The above is all the contents of the article "how to determine whether the string is all 0 by javascript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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.
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.