Javatpoint Logo
Javatpoint Logo

JavaScript string repeat() method

The 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.

Syntax

The syntax shows how to use JavaScript's repeat() methods with a string value.

Explanation

  • The "string_var" copies the given input string data.
  • The "counts" is a required input argument. It shows the required number of copies of the string.

Supported Browsers

The following browsers support the javascript string repeat method.

  • Google Chrome version 41 or later
  • Edge 12 or higher
  • Firefox versions 24 or later
  • Opera version 28 or later
  • Safari version 9 or later
  • Internet Explorer 11 or above.

Note: - Internet Explorer 11 and earlier version does not support the repeat() method.

Examples

The 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.

JavaScript string repeat() method

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.

JavaScript string repeat() method

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.

JavaScript string repeat() method

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.

JavaScript string repeat() method

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.

JavaScript string repeat() method

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.

JavaScript string repeat() method

Conclusion

The repeat() method shows the multiple times of the string data. We can operate and manipulate the value directly using the javascript function.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA