The dojox.collections module contains the Iterator class. The Iterator class can be used to iterate over dojox.collections objects and JavaScript arrays.
map()method?The map() function will execute a callback function to all the elements in the collection.
map(callbackFn, scope);
This method takes two arguments:
callbackFn(): This is a function that will be executed for all elements of the dojox.collections objects in the order of the iteration.
scope: This reflects the this scope of the callback function.
Let's create an array that contains a list of numbers and use the map() method to loop through the array and multiply each element by 2 and print it.
Line 6: We load the dojo library from the CDN server.
Line 8: We load the dojox/collections/ArrayList module.
Line 9: After the ArrayList class is loaded, we create a new ArrayList object with value [1,2,3,4].
Line 10: We use the getIterator() method to get the iterator object for the ArrayList object.
Lines 14–16: We use the map() method to execute a method for each element of the ArrayList. Inside the function, we multiply each element of ArrayList by 2 and print the value.
Free Resources