Raphael Asked: 2020-06-17 17:36:23 +0800 CST 2020-06-17 17:36:23 +0800 CST 2020-06-17 17:36:23 +0800 CST how to create an array of arrays? [closed] 772 I try to get my data to be returned as an array of objects: convert to this: it's possible? Some alternative? * although in the image only one object is returned, it could be many. javascript 1 Answers Voted Best Answer Fernando Carrascosa 2020-06-18T01:48:11+08:002020-06-18T01:48:11+08:00 By iterating using the method .map()over your array of objects, you can convert the structure you receive practically at your convenience. In this case, generating a new one Arraywith the structure you want. I leave you an example. const originalArr =[ {fecha: "Ene", total_mes: 20.00}, {fecha: "Feb", total_mes: 24.00}, {fecha: "Mar", total_mes: 10.00}, {fecha: "Abr", total_mes: 15.00}, {fecha: "May", total_mes: 66.66}, {fecha: "Jun", total_mes: 12.00}, {fecha: "Jul", total_mes: 25.00}, {fecha: "Ago", total_mes: 15.00}, {fecha: "Sep", total_mes: 2.00}, {fecha: "Oct", total_mes: 5.00}, {fecha: "Nov", total_mes: 1.00}, {fecha: "Dic", total_mes: 125.00}, ] const myNewArr = originalArr.map(el => [el.fecha, el.total_mes]); console.log(myNewArr);
By iterating using the method
.map()
over your array of objects, you can convert the structure you receive practically at your convenience.In this case, generating a new one
Array
with the structure you want.I leave you an example.