index.js
function buildLayers(layersObject) {
	// Array of layers
	var layers = [];

	if (layersObject) {
		// Iterate over all layers
		for (var int = 0; int < layersObject.length; int++) {
			// One layer
			var singleLayer = layersObject[int];

			// Build a new layer object
			var layer = {};

			// Determine name from GetCapabilities document
			if (singleLayer.Name) {
				if (singleLayer.Name[0]) {
					layer.Name = singleLayer.Name[0];
				}
			}

			// Determine title from GetCapabilities document
			if (singleLayer.Title) {
				if (singleLayer.Title[0]) {
					layer.Title = singleLayer.Title[0];
				}
			}

			// Determine abstract from GetCapabilities document
			if (singleLayer.Abstract) {
				if (singleLayer.Abstract[0]) {
					layer.Abstract = singleLayer.Abstract[0];
				}
			}

			layer.Layer = buildLayers(singleLayer.Layer);

			// Determine layer name if not available
			layer.Name = determineLayerName(layer);

			// Determine layer title if not available
			if (!(layer.Title)) {
				layer.Title = layer.Name;
			}

			// Add layer to the array
			layers.push(layer);
		}
	}

	return layers;
}
function buildLayers(layersObject) {
	// Array of layers
	var layers = [];

	if (layersObject) {
		// Iterate over all layers
		for (var int = 0; int < layersObject.length; int++) {
			// One layer
			var singleLayer = layersObject[int];

			// Build a new layer object
			var layer = {};

			// Determine name from GetCapabilities document
			if (singleLayer.Name) {
				if (singleLayer.Name[0]) {
					layer.Name = singleLayer.Name[0];
				}
			}

			// Determine title from GetCapabilities document
			if (singleLayer.Title) {
				if (singleLayer.Title[0]) {
					layer.Title = singleLayer.Title[0];
				}
			}

			// Determine abstract from GetCapabilities document
			if (singleLayer.Abstract) {
				if (singleLayer.Abstract[0]) {
					layer.Abstract = singleLayer.Abstract[0];
				}
			}

			layer.Layer = buildLayers(singleLayer.Layer);

			// Determine layer name if not available
			layer.Name = determineLayerName(layer);

			// Determine layer title if not available
			if (!(layer.Title)) {
				layer.Title = layer.Name;
			}

			// Add layer to the array
			layers.push(layer);
		}
	}

	return layers;
}
function buildLayers ( layersObject ) { // Array of layers var layers = [ ] ; if ( layersObject ) { // Iterate over all layers for ( var int = 0 ; int < layersObject . length ; int ++ ) { // One layer var singleLayer = layersObject [ int ] ; // Build a new layer object var layer = { } ; // Determine name from GetCapabilities document if ( singleLayer . Name ) { if ( singleLayer . Name [ 0 ] ) { layer . Name = singleLayer . Name [ 0 ] ; } } // Determine title from GetCapabilities document if ( singleLayer . Title ) { if ( singleLayer . Title [ 0 ] ) { layer . Title = singleLayer . Title [ 0 ] ; } } // Determine abstract from GetCapabilities document if ( singleLayer . Abstract ) { if ( singleLayer . Abstract [ 0 ] ) { layer . Abstract = singleLayer . Abstract [ 0 ] ; } } layer . Layer = buildLayers ( singleLayer . Layer ) ; // Determine layer name if not available layer . Name = determineLayerName ( layer ) ; // Determine layer title if not available if ( ! ( layer . Title ) ) { layer . Title = layer . Name ; } // Add layer to the array layers . push ( layer ) ; } } return layers ; }
It builds a simple array with layer information.

@param {object}
layersObject Object with layers from JSON. That JSON have to
converted by the original XML GetCapabilities document.
@returns {array} Array with layers and sublayers
It builds a simple array with layer information .