I have an object in which the values are integers. Something like: {cat: 2, dog: 1, bird: 4}
I want to create an array in which the key in the object is included in the array the same number of times as the value. So, in this instance: ["cat", "cat", "dog", "bird", "bird", "bird", bird"]
The keys will always be the same, but a value may be zero.
I can see one way I could do it - for each key I can retrieve the value then push the word to the array that number of times. But that requires several lines of code for each of my keys (of which there are significantly more than in this example). I've tried searching for a cleaner solution, but no luck. Any suggestions?