Array<T>

Summary

System.Array<T> is the wrapper class for arrays.

Description

System.Array<T> is the wrapper class for arrays.

JS++ is a superset of the ECMAScript 3 JavaScript specification. The following methods were not standardized in JavaScript until ECMAScript 5:

  • System.Array<T>.indexOf
  • System.Array<T>.lastIndexOf
  • System.Array<T>.every
  • System.Array<T>.some
  • System.Array<T>.filter
  • System.Array<T>.map
  • System.Array<T>.forEach
  • System.Array<T>.reduce
  • System.Array<T>.reduceRight

For web browsers that are not ECMAScript 5-compatible, the above methods will be polyfilled automatically by the JS++ compiler if and only if the method of interest gets used.

Differences to JavaScript

  • sort() performs a numeric sort if the underlying Array type is byte, signed byte, short, unsigned short, int, unsigned int, long, unsigned long, char, float, or double. JavaScript's array sort() method will perform a string comparison so [ 1, 2, 10 ] ends up being sorted as [ 1, 10, 2 ].

Examples

Instantiation
1
2
3
import System;
 
System.Array<int> arr = new System.Array<int>([1, 2, 3]);
Auto-boxing
1
2
3
import System;
 
System.Array<int> arr = [1, 2, 3];
Without the wrapper class
1
int[] str = [1, 2, 3];

Methods

  • Array (Constructor)

    Constructs a System.Array<T> object.

  • clear

    Clears the array by removing all elements from the array.

  • concat

    Concatenates the specified element to the end of the array.

  • contains

    Checks if an element is in the array.

  • count

    Counts the occurrences of a value inside the array.

  • every

    Tests if the specified condition is valid for every array element.

  • fill

    Fills the array with the specified value.

  • filter

    Returns a new array with all elements of the original array that pass the specified condition.

  • first

    Returns the first element of the array.

  • forEach

    Executes the specified function on each array element.

  • indexOf

    Returns the first index of the search element in the array.

  • isEmpty

    Checks if the array is empty and contains zero elements.

  • join

    Returns a string representation of the array with each element separated by commas.

  • last

    Returns the last element of the array.

  • lastIndexOf

    Returns the last index of the search element in the array.

  • length

    Returns the size of the array.

  • map

    Returns a new array with the specified operation applied to all elements of the original array.

  • pop

    Removes the last element of the array.

  • push

    Adds an element to the end of the array.

  • reduce

    Applies an accumulator function (on each array element from left to right) to reduce the array to a single value.

  • reduceRight

    Applies an accumulator function (on each array element from right to left) to reduce the array to a single value.

  • remove

    Removes the array element at the specified index.

  • repeat

    Repeats the array elements for the specified number of times.

  • reverse

    Reverses the elements of the array.

  • shift

    Removes the first element of the array.

  • slice

    Returns a subset of the array beginning at the specified index until the end of the array.

  • some

    Tests if the specified condition is valid for at least one array element.

  • sort

    Sorts the elements of the array.

  • splice

    Removes elements from the specified starting array index to the end of the array.

  • toExternal

    Constructs a new external array with each element of the internal Array<T> converted to external (via an element-by-element toExternal call). If an element does not implement the System.IExportable interface, a System.Exceptions.ConversionException will be thrown.

  • toString

    Returns a string representation of the array value.

  • unshift

    Adds the specified element to the beginning of the array.

  • valueOf

    Returns the primitive array value wrapped by the System.Array<T> object.

Share

HTML | BBCode | Direct Link