Get the App
SLTechnology News&Howtos  ›  Development  › 

How JavaScript uses the repeat function

Shulou Source: shulou.com Published: 2022-06-01 02:38:20 09月22日 Update

This article mainly shows you "JavaScript how to use repeat function", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "JavaScript how to use repeat function" this article.

Repeat: generate a duplicate string consisting of n str, which can be modified to fill in an array, etc.

Function repeat (str, n) {let res ='; while (n) {if (n% 2 = 1) {res + = str;} if (n > 1) {str + = str;} n > > = 1;} return res} / / repeat ('123 repeat Magazine 3) = > 123123123 is all the contents of the article "how to use repeat functions 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!

Tags: Functions content articles learning help characters strings arrays easy to understand more organization knowledge editing industry information information channels channels generation research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Huawei vpn Microsoft