Q:

Create a variable into the loop "for"

I work on a function for create a arrays into a array.
I have a JSON like this :
[
    [
        {"data_name":"dn1","defaut_name":"1F-27","occurrence":5},
        {"data_name":"dn1","defaut_name":"20-34","occurrence":1}
    ],[
        {"data_name":"bm1","defaut_name":"13-02","occurrence":4}
    ],[
        {"data_name":"dn2","defaut_name":"1F-27","occurrence":3},
        {"data_name":"dn2","defaut_name":"20-34","occurrence":1}
    ],[
        {"data_name":"bm2","defaut_name":"13-02","occurrence":4}
    ],[
        {"data_name":"bm3","defaut_name":"13-02","occurrence":3}
    ],[
        {"data_name":"bm4","defaut_name":"13-02","occurrence":3}
    ]
]

And I want a result like this :
[
    [5,4,3,4,3,3],
    [1,0,1,0,0,0]
]

This corresponds to the concatenation of occurrences.
I tried with a loop for but it doesn't work.
var data = [];
for (var i in chartData) {
    var array = [];
    for (var j in chartData[i]) {
        array.push(chartData[i][j].occurrence)
    }
    data.push(array);
}

Thank for your help.

A:

You could simply use the result you have to make the output you are looking for:

var chartData = [
    [
        {"data_name":"dn1","defaut_name":"1F-27","occurrence":5},
        {"data_name":"dn1","defaut_name":"20-34","occurrence":1}
    ],[
        {"data_name":"bm1","defaut_name":"13-02","occurrence":4}
    ],[
        {"data_name":"dn2","defaut_name":"1F-27","occurrence":3},
        {"data_name":"dn2","defaut_name":"20-34","occurrence":1}
    ],[
        {"data_name":"bm2","defaut_name":"13-02","occurrence":4}
    ],[
        {"data_name":"bm3","defaut_name":"13-02","occurrence":3}
    ],[
        {"data_name":"bm4","defaut_name":"13-02","occurrence":3}
    ]
];

var data = [];
for (var i in chartData) {
    var array = [];
    for (var j in chartData[i]) {
        array.push(chartData[i][j].occurrence)
    }
    data.push(array);
}

var newData = [ [], [] ];
for (var i in data) {
    newData[0].push(data[i][0]);
    newData[1].push(data[i][1] || 0);
}

console.log(newData);

