Aadi
Aadi

Reputation: 7109

Getting subarrays of JSON response using Mootools

Is there any altenative for Jquery $.map(array, function(item)) in mootools.

How can I change following JSON result

{"totalResultsCount":2,"geonames":[{"countryName":"India","name":"Cochin"},{"countryName":"Canada","name":"Cochin"},{"countryName":"Venezuela","name":"Cochina"}]}

as

[{"countryName":"India","name":"Cochin"},{"countryName":"Canada","name":"Cochin"},{"countryName":"Venezuela","name":"Cochina"}]

I need mootools alternate for following jquery

    function(data) {
    response($.map(data.geonames, function(item) {


        return {
            label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,

        }

}))

Any help please

Upvotes: 0

Views: 194

Answers (1)

Dimitar Christoff
Dimitar Christoff

Reputation: 26165

er, you should've probably read the mootools documentation on Arrays first. It is nearly identical, posting this just says 'I cannot be bothered to look it up'.

You can use the native Array type map method Array.map(data.geonames, function(item) {}) - see http://jsfiddle.net/TD2rK/1/ - or call it via the prototype from data.geonames.map(function(item) {}) - see http://jsfiddle.net/TD2rK/

Array.map() - method #1 - will be future proof with AMD and non-extended prototypes (think mootools 2.0 aka MILK).

Upvotes: 1

Related Questions