Creating Array of Array From Array of Object

How do I create array of array from array of object? Currently I am using javascript but the result is different. I believe there is a bug.

var income = [
{"_credit": {“category”: “drinks”}, “debit_amount”:200},
{"_credit": {“category”: “drinks”}, “debit_amount”:400},
{"_credit": {“category”: “drinks”}, “debit_amount”:500},
]

var newIncome = [];

for (var i = 0; i < income.length; i++) {
newIncome.push([income[i]._credit.category, “”, income[i].debit_amount]);
};

And the result that I get is
[[drinks, 1100], [drinks, 400], [drinks, 500]],

The first array will sum up all the amount.

Hi, you can reach the result with the following formula:

MAP(data.income, [item._credit.category, item.debit_amount])

1 Like

@Mari ,

How to create the variable? I can do it using list of lists of texts. But in the formula, it says lists item are incompatible

Hi, the incompatibility might be because debit_amount is a number. You can convert it to a string in the formula using MAP(data.income, [item._credit.category, STRING(item.debit_amount)])

Then you’ll have a list of lists of texts :slight_smile:

Got it. Thanks @Mari