DEV Community

Discussion on: 10 JavaScript string methods you should know

 
frugencefidel profile image
Frugence Fidel

Actually repeat is easy to read

If you want to make string of 52 a's with repeat is so easy

  const a = 'a'.repeat(52);
  console.log(a); // "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  console.log(a.length); // 52
Thread Thread
 
siddharthray profile image
siddharthray

Array index starts from 0 which means it will print 52 times.

Thread Thread
 
diek profile image
diek

Yass, and since join acts as 'glue', using 'a' as glue for 52 nothings will print 'a' 51 times. Give it a try ;)