I want to iterate an array of objects to create one object, the properties of which are named for the current object in the iteration and the values of which use data from the current.
$.each(data, function(idx, obj) {
baseLayers[idx] = new Array();
baseLayers[idx][obj.name] = new L.TileLayer(obj.url, {maxZoom: 18, id: obj.key, attribution: mbAttr});
});
at the end, I want to get result an object like this
baseLayers = {
'Map Box': new L.TileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {maxZoom: 18, id: 'examples.map-i875mjb7', attribution: mbAttr}),
'OSM': new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 18, attribution: mbAttr})
};
obj.name$.eachblock when I tried to get length ofbaseLayer[0]it gives as0but, it has keybaseLayers[0]['Map Box']