I have an object like so:
{ green: 2, blue: 1, red: 2}
How can I turn it into an array that looks like this:
[ \'green\', \
var data={ green: 2, blue: 1, red: 2}; var newData=[]; for(let i in data){ for(let j=0;j<data[i];j++){ newData.push(i); } } console.log('newData = ', newData);
output
newData = ["green", "green", "blue", "red", "red"]