JavaScript string repeat() methodThe ECMAScript6 (ES6) provides the string repeat() feature to repeat the given string. The sting can provide data to display the required time with function and event. The repeat method does not affect the original data, but displays require time the similar data. In other words, the string repeat method shows a new string with the method work on the script tag. The repeat() method copies the given string in the required number. The negative values of the repeat method show an error, and the zero value does not display any data. The positive value shows the string value. SyntaxThe syntax shows how to use JavaScript's repeat() methods with a string value. Explanation
Supported BrowsersThe following browsers support the javascript string repeat method.
Note: - Internet Explorer 11 and earlier version does not support the repeat() method.ExamplesThe following examples show the multiple data types with different events. Example 1: the following example shows the basic string repeat method in the javascript. We can copy the input string and display the value by using one and two counts. Output The image shows repeat methods information as an output. Example 2: the following example shows the basic string repeat method in the javascript. We can use two repeat methods with the onclick function. If we click the button, it shows the string value count. Output The image shows repeat methods information as an output. Example 3: the following example shows the basic string repeat method in the javascript. We can use the repeats method with the addition and decimal values. We can add the count and shows the string. Output The image shows repeat methods information as an output. Example 4: the following example shows the basic string repeat method in the javascript. We can copy the input string and display the value by using one and two counts. The negative count shows a type error in the console tab, and the o count shows no value. Output The image shows repeat methods information as an output. Example 5: the following example shows the basic string repeat method in the javascript. We can use the repeats method with the addition and decimal values. We can add the count when we click the button. Output The image shows repeat methods information as an output. Example 6: the following example shows the basic string repeat method in the javascript. We can use direct data with the repeat method. We do not need any variable to get string data. The image shows repeat methods information as an output. ConclusionThe repeat() method shows the multiple times of the string data. We can operate and manipulate the value directly using the javascript function.
Next TopicThe textContent in Javascript
|