how to generate a json array in javascript adding id

0

As I can make a script where I can load the following structure into a json, the idea is to load the values with push.

1 {1,2,3,4,5,6}, 2 {10,11,12,13,14}

    
asked by avilac3 23.10.2017 в 08:35
source

1 answer

0

Good, a solution for your problem would go through the following: create a json object that has the following structure:

var jsonObject1 = {
    'id': 1,
    'arrayNumeros': [1,2,3,4,5,6]
}
var jsonObject2 = {
        'id': 2,
        'arrayNumeros': [10,11,12,13,14]
    }

This way you would have an array of jsonObject such that:

var arrayJsonObjects = [];

arrayJsonObjects.push(jsonObject1);
arrayJsonObjects.push(jsonObject2);

With what I would give you the following output:

[{"id":1,"arrayNumeros":[1,2,3,4,5,6]},{"id":2,"arrayNumeros":[10,11,12,13,14]}]

I hope you have helped, greetings!

    
answered by 23.10.2017 в 08:49