Chartjs-I need to build an array of arrays, having trouble conceptualizing

3๐Ÿ‘

โœ…

I think youโ€™ve made it much more complicated than need be. Just select the td.goal elements, and use .map() to return an object to a new array with the values from the current goal.

var result = $("table.card tr[class^=section] td.goal").map(function(i, tr) {
    var goal = $(this);
    return {
        value: parseInt(goal.text(), 10),
        color:goal.prev().css('color') || '#000000'
    };
}).toArray();

1๐Ÿ‘

Use .map()

Fiddle Demo

var data = $('.card tr').map(function () {
    $this = $(this);
    return {
        value: $this.find('.goal').text(),
        color: $this.find('.label').css('color') //will return like "rgb(194, 101, 88)"
    }
}).get();
console.log(data);

Leave a comment