What is the map method in the iterator in dojox?

Iterators

The dojox.collections module contains the Iterator class. The Iterator class can be used to iterate over dojox.collections objects and JavaScript arrays.

What is the map()method?

The map() function will execute a callback function to all the elements in the collection.

Syntax

map(callbackFn, scope);
Syntax of map() function

Parameters

This method takes two arguments:

  1. callbackFn(): This is a function that will be executed for all elements of the dojox.collections objects in the order of the iteration.

  2. scope: This reflects the this scope of the callback function.

Code example

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.

  • HTML
Console
Using map() method of iterator

Code explanation

  • 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

Copyright ©2025 Educative, Inc. All rights reserved