-2

I want to generate n' number of same characters which will be stored in a var. Like gggggggggggggggggggg

But not using a separate function.

Is there any api for that?

Praveen Aanand
  • 125
  • 2
  • 6
  • 2
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat – Barmar May 16 '20 at 06:04
  • What do you mean by `n'`? How is that different from `n`? – Barmar May 16 '20 at 06:05
  • Please visit [help], take [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output, preferably in a [Stacksnippet](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/) – mplungjan May 16 '20 at 06:06
  • 2
    @gorak: `console.log('g'.repeat(10));` – mplungjan May 16 '20 at 06:10

1 Answers1

0

You can use repeat function for Strings in JS. It works like this,

const str = "some string";
console.log(str.repeat(n));

This will repeat str , n number of times