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
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 fromdata.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).