With lodash you can iterate the array with _.flatMap()
. Create the the callback using _.overArgs()
that will pass the value (via _.identity()
) and the key (wrapped with _.constant()
) to _.times()
:
const obj = {
products: {
bread: 1,
milk: 2,
cheese: 2,
chicken: 1,
}
}
const result = _.flatMap(obj.products, _.overArgs(_.times, [_.identity, _.constant]))
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js"></script>