Format array in specific format with mapping [duplicate]

  arrays, javascript, mapping

I’m not sure if this is even possible to do with mapping or other way.

I have 10 arrays, and I would like to "re-compose" in a specific format:

Please see above example I have created

https://jsfiddle.net/03x1vebc/

Is this possible?
Thanks.

var data_1 = ["23","11","4","77","9","123"];
var data_2 = ["5","4","122","41","74","61"];
var data_3 = ["6","55","14","12","75","9"];
var data_4 = ["8","5","5","3","1","7"];
var data_5 = [];
var data_6 = ["25","63","31","53","21","64"];
var data_7 = [];
var data_8 = ["74","41","64","51","23","36"];
var data_9 = [];
var data_10 = ["7","75","34","99","74","15"];

var title_1 = "Title_1";
var title_2 = "Title_2";
var title_3 = "Title_3";
var title_4 = "Title_4";
var title_5 = "";
var title_6 = "Title_6";
var title_7 = "";
var title_8 = "Title_8";
var title_9 = "";
var title_10 = "Title_10";

// expected format (because 5, 7 and 9 are empty they are not included in the data result) but maybe in the next search 5, 7 and 9 will contain data so would need this to be variable;

[
        {
            title: "Title_1",
            data: [23, 11, 4, 77, 9, 123]
        },
        {
            title: "Title_2",
            data: [5, 4, 122, 41, 74, 61]
        },
        {
            title: "Title_3",
            data: [6, 55, 14, 12, 75, 9]
        },
        {
            title: "Title_4",
            data: [8, 5, 5, 3, 1, 7]
        },
        {
            title: "Title_6",
            data: [25, 63, 31, 53, 23, 36]
        },
        {
            title: "Title_8",
            data: [74, 41, 64, 51, 23, 36]
        },
        {
            title: "Title_10",
            data: [7, 75, 34, 99, 74, 15]
        }
    ]

Source: Ask Javascript Questions

LEAVE A COMMENT