Ruby => JS: Fill a New Array

Tech: javascript, ruby

Challenge: in a React app, I have to format some data coming from an API… I want to fill out the API data array to a certain length with empty strings. Coming from a Ruby background, I have grown very used to Ruby shortcuts. How do I tackle in JS?


incoming API data = ['string', 'string']

application needs an array with length 5… likeĀ ['string', 'string', "", "", ""]


In Ruby, I calculate the difference in lengths and create a new array with empty strings, contained within the .new args: - apiArray.length, "")


Javascript is just slightly different. Just need to combine new Array with an ES6 prototype!

new Array(5 - apiArray.length).fill("")