From OpenSCADAWiki
Jump to: navigation, search

Array provides the special property "length" to get the array size "var = arr.length;". Also array provides the following functions:

  • string join( string sep = "," ), string toString( string sep = "," ), string valueOf( string sep = "," ) — returns the string with the array elements separated by sep or the character ','.
  • Array concat( Array arr ); — adds to the initial array the elements of the arr array. Returns the initial array with changes.
  • int push( ElTp var, ... ); — places the element(s) var to the end of the array, as to the stack. Returns the new array size.
  • ElTp pop( ); — deletes of the last element of the array and returns of its value, as from the stack.
  • Array reverse( ); — changes the order of the elements of the array. Returns the initial array with the changes.
  • ElTp shift( ); — shifts of the array to the top. The first element is removed and its value is returned.
  • int unshift( ElTp var, ... ); — shifts element(s) var to the array. The first element to the 0, second to the 1 and so on.
  • Array slice( int beg, int end ); — returns an array fragment from beg to end (exclude). If the value of beginning or end is negative, then the count is made from the end of the array. If the end is not specified, then the end is the end of the array.
  • Array splice( int beg, int remN, ElTp val1, ElTp val2, ... ); — inserts, deletes or replaces the elements of the array. Returns the removed elements array. Firstly it is made the removing of elements from the position beg and in the quantity of remN, and then the values val1 are inserted and so on, beginning from the position beg.
  • int indexOf( ElTp var, int start = 0 ); — returns the array index of the required variable var in the original row from the position start. If the initial position is not specified then the search starts from the beginning. If the search variable is not found then "-1" is returned.
  • int lastIndexOf( ElTp var, int start = {end} ); — returns the array index of the required variable var in the original row from the position start when searching from the end. If the initial position is not specified then the search begins from the end. If the search variable is not found then "-1" is returned.
  • double sum(int beg, int end); — sum of the array values part from the position beg to end, excluding.
  • Array sort( ); — sorts array elements in the lexicographical order.