Product SiteDocumentation Site

5.3.6.2. insert


>>-insert(item-+--------+-)------------------------------------><
               +-,index-+

Returns an Array-supplied index for item item, which is added to the Array. The inserted item follows an existing item with index index in the Array ordering. If index is the Nil object, item becomes the first item in the Array. If you omit index, the item becomes the last item in the Array.
Inserting an item in the Array at position index will cause the items in the Array after position index to have their indexes shifted by the Array object. The index values for any items in the Array are incremented by the insertion.

Example 5.129. Array class - insert method

musketeers=.Array~of("Porthos","Athos","Aramis") /* Creates Array MUSKETEERS        */
                                                 /* consisting of: Porthos         */
                                                 /*                Athos           */
                                                 /*                Aramis          */
musketeers~insert("D'Artagnan",1)    /* Adds D'Artagnan after Porthos  */
                                          /* Array is now: Porthos           */
                                          /*              D'Artagnan   */
                                          /*              Athos             */
                                          /*              Aramis            */
/* Alternately, you could use */
musketeers~insert("D'Artagnan",.nil) /* Adds D'Artagnan before Porthos */
                                          /* Array is now:  D'Artagnan  */
                                          /*               Porthos          */
                                          /*               Athos            */
                                          /*               Aramis           */
/* Alternately, you could use */
musketeers~insert("D'Artagnan")      /* Adds D'Artagnan after Aramis   */
                                          /* Array is now:  Porthos          */
                                          /*               Athos            */
                                          /*               Aramis           */
                                          /*               D'Artagnan  */