I have an object and I want to fill an array with the object property and repeat each property a number of times, based on its value. An example:
obj = {
watches: 3
rings: 1
}
// => ['watches', 'watches', 'watches', 'rings']
Below is what I have so far. I'm having a hard time figuring how to repeat each property based on the associated value?
function arrayBuilder(obj) {
let objToArr = [];
for (let [property, value] of Object.entries(obj)) {
objToArr.push(property);
}
return objToArr;
}
console.log(arrayBuilder({watches: 3, rings: 1}));
// => [ 'watches', 'rings' ]