Skip to main content

Insert Into List At Index

Inserts an item into the list at a certain index and returns the list.

Insert Into List At Index block

Description

The Insert Into List At Index block inserts an item into the list at a certain index and returns the list. This is a code block part of the Lists drawer.

Usage

Use Insert Into List At Index to add elements at specific positions within a list. This is useful for maintaining ordered lists, inserting values at calculated positions, or building lists dynamically with precise control over element placement.

Syntax

Inputs:

  • Any type of element/block to insert
  • A list to insert into
  • A number (the index position)

Notes

  • Returns the modified list with the new element inserted
  • Elements after the insertion point are shifted to higher indices
  • The original list is modified and returned
  • List indices in StarLogo Nova start at 1