1

In python to get an array of X strings (repeated) I can do:

>>> 'hi' * 3
# 'hihihi'

Perhaps 'array' isn't the correct term but hopefully the above example clarifies what I mean. Is there a way to do this in javascript without using a loop? Or what would be the most straightforward way to do this? Currently I'm using a c-ish loop:

> for (let i=0, x=''; i< 3; i++) {x += 'hi'}
// "hihihi"
samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58

0 Answers0