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/01 Report--
这篇文章主要介绍JavaScript如何合理使用循环,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
合理使用循环
如果多段代码实际上负责的是一些重复性的工作,那么可以用循环代替,使代码量更少。
// 判断是什么浏览器function getBrowser(){ const str = navigator.userAgent; if (str.includes('QQBrowser')) { return 'qq'; } else if (str.includes('Chrome')) { return 'chrome'; } else if (str.includes('Safari')) { return 'safri'; } else if (str.includes('Firefox')) { return 'firefox'; } else if(explorer.indexOf('Opera') >= 0){ return 'opera'; } else if (str.includes('msie')) { return 'ie'; } else { return 'other'; }};// 循环判断,将对应关系抽象为配置,更加清晰明确function getBrowser(){ const str = navigator.userAgent; const list = [ {key: 'QQBrowser', browser: 'qq'}, {key: 'Chrome', browser: 'chrome'}, {key: 'Safari', browser: 'safari'}, {key: 'Firefox', browser: 'firefox'}, {key: 'Opera', browser: 'opera'}, {key: 'msie', browser: 'ie'}, ]; for (let i = 0; i < list.length; i++) { const item = list[i]; if (str.includes(item.key)) {return item.browser}; } return 'other';}以上是"JavaScript如何合理使用循环"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
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.