I have this simple JSON file (test.json):
{"personnes":[
{
"name":"Super",
"firstname":"Mario",
"adresse":["45 rue du poirier","6700","Strasbourg"],
"departement": "bas-rhin",
},
{
"name":"Super",
"firstname":"Luigi",
"adresse":["10 rue du muguet","6700","Strasbourg"],
"departement": "eure",
}
]}
For some reason, I need to get the "division" values, which will be stored in a single array, such as: ["bas-rhin","eure"]
I found out that I $.makeArray()can do this work, but I did not know how to do it. Here is my jQuery:
$( document ).ready(function() {
$.getJSON( "ajax/test.json", function( data ) {
console.log('loaded');
var departement;
var departements = $.each(data.personnes, function (index, personne) {
departement = personne.departement;
var arr = $.makeArray(departement);
console.log(arr)
});
});
});
With this code, I get 2 separate arrays: ["eure"]and ["bas-rhin"].
Here is the question: how can I solve it and get these values in one array?