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 =
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
Array.new(5 - apiArray.length, "")
new Array(5 - apiArray.length).fill("")