Hello, guys. I’m trying to “format” one array of objects correctly, but the title item one is not working as I want.
Code:
var title1 = "title1";
var title2 = "";
var title3 = "title3";
var title4 = "";
var title5 = "title5";
var titles = [title1, title2, title3, title4, title5];
var data1 = [10.0, 8.04, 11.0, 8.33, 9.01, 5.10, 3.59, 4.58, 9.18, 10.84];
var data2 = [];
var data3 = [7.1, 9.1, 3.7, 8.6, 8.3, 7.1, 7.0, 8.2];
var data4 = [];
var data5 = [6.12, 18.1, 12.1, 48.1, 8.3, 3.9, 6.2, 9.9];
var comb = [].concat(data1, data2, data3, data4, data5);
const rows = comb.reduce(function (rows, key, index) {
return (index % 2 == 0 ? rows.push([key])
: rows[rows.length - 1].push(key)) && rows;
}, []);
var combined = rows.map(function combineTitleData(dataItem, index) {
return {
name: titles[dataItem.lenght],
data: dataItem
};
}).filter(function removeEmpty(item) {
return item.data.length;
});
console.log(combined);
Everything is working fine but the titles, Instead of adding title 1 to all arrays created from data1, title 2… for data2… << >> title5 for data5 the titles[dataItem.lenght] returns the same title for all the objects.
Where I’m messing it, or what’s missing in the code to format properly the title according to that array data?
JSFIDDLE: https://jsfiddle.net/9uxpw53q/
Any help would be very appreciated,
Thanks.