Is it possible to make an array from my reduce result?
For Example this code
const fruitBasket = ['banana', 'cherry', 'orange', 'apple', 'cherry', 'orange', 'apple', 'banana', 'cherry', 'orange', 'fig'];
const count = fruitBasket.reduce((tally, fruit) => {
tally[fruit] = (tally[fruit] || 0) + 1;
return tally;
}, {})
console.log(count) // { banana: 2, cherry: 3, orange: 3, apple: 2, fig: 1 }
Can I get an array from count?
Something like
const NewArrayName = [
{fruit: "banana", num: "2"},
{fruit: "orange", num: "3"}
]; ```
{"orange" : "2", "banana" : "3"}
is not an array – CertainPerformance["orange" : "2", "banana" : "3"]
is not a valid syntax. Please create a minimal reproducible example – adiga