How to insert an element at a specific index with dojox

What is Dojo?

The Dojo is a JavaScript toolkit (library) that provides many utility modules and functions to create a web application. We can save time and speed up the development process using the predefined Dojo modules. Dojo includes language utilities, UI components, and more.

Insert an element at a specific index

We can use the insert method of the dojox.collections.ArrayList module to insert an element at a specific index of the ArrayList.

Syntax

insert(index, value);
Syntax of insert method

This method takes two arguments

  1. index: This is the index to which the new element is to be inserted.

  2. value: This is the value to be inserted.

Code example

Let's look at the code below:

Console
Using insert method to insert an element at specific index of the ArrayList

Code explanation

In the above code snippet:

  • 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 [2,3,4] .

  • Line 12: We use the insert method to insert the value 0 and 0th index of the ArrayList. After insertion, the list will be [0,2,3,4] .

  • Line 15: We use the insert method to insert the value 1 at 1st index of the ArrayList. After insertion, the list will be [0,1,2,3,4] .

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved