JsArray

class JsArray[A] extends JsIterable[A]

To construct a new array with uninitialized elements, use the constructor of this class. To construct a new array with specified elements, as if you used the array literal syntax in JavaScript, use the companion object's apply method instead.

Note that Javascript === equality semantics apply. JsArray does not know anything about Scala equals method or the case classes structural equality.

Type parameters:
A

Type of the elements of the array

Constructor:

Creates a new array of length 0.

Companion:
object
trait JsIterable[A]
class Object
trait Any
class Object
trait Matchable
class Any

Value members

Constructors

def this(arrayLength: Int)

Create a new array with the given length (filled with js.undefined irrespective of the type argument A!).

Create a new array with the given length (filled with js.undefined irrespective of the type argument A!).

See companion object for more factories.

Value parameters:
arrayLength

Initial length of the array.

Concrete methods

def apply(index: Int): A

Access the element at the given index.

Access the element at the given index.

Implicitly added by RichJsArray
def asScalaJs: Array[A]
Implicitly added by RichJsArray
def concat[B >: A](items: JsArray[_ <: B]*): JsArray[B]

Create a new array consisting of the elements in the this object on which it is called, followed in order by, for each argument, the elements of that argument

Create a new array consisting of the elements in the this object on which it is called, followed in order by, for each argument, the elements of that argument

def filter(passes: Function1[A, Boolean]): JsArray[A]

Create a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.

Create a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.

def filter(passes: Function2[A, Int, Boolean]): JsArray[A]
def forEach(cb: Function1[A, Any]): Unit
Implicitly added by RichJsArray

Note: this implementation is faster than calling into JS native forEach.

Note: this implementation is faster than calling into JS native forEach.

def forEachWithIndex(cb: Function2[A, Int, Any]): Unit
Implicitly added by RichJsArray

Similar to the native two-argument version of forEach

Similar to the native two-argument version of forEach

def indexOf(item: A): Int
def join(seperator: String): String

Join all elements of an array into a string.

Join all elements of an array into a string.

separator Specifies a string to separate each element of the array. The separator is converted to a string if necessary. If omitted, the array elements are separated with a comma.

def length: Int

Length of the array.

Length of the array.

def length_=(v: Int): Unit

Set the length of the array.

Set the length of the array.

If the new length is bigger than the old length, created slots are filled with undefined (irrespective of the type argument A!).

If the new length is smaller than the old length, the array is shrunk.

See also:
def map[B](project: Function1[A, B]): JsArray[B]

Create a new array populated with the results of calling a provided function on every element in the calling array.

Create a new array populated with the results of calling a provided function on every element in the calling array.

def mapWithIndex[B](project: Function2[A, Int, B]): JsArray[B]
def pop(): A

Remove the last element from an array and returns that element.

Remove the last element from an array and returns that element.

Returns js.undefined if array is empty.

def push(items: A*): Int

Mutate an array by appending the given elements and returning the new length of the array.

Mutate an array by appending the given elements and returning the new length of the array.

def reduce(f: Function2[A, A, A]): A
Value parameters:
f

(accumulator, nextValue) => nextAccumulator On first call of f, accumulator is array[0], and nextValue is array[1]. If array only has one item, array[0] is returned without calling f. Note: throws exception if array is empty.

def reduce[B](f: Function2[B, A, B], initial: B): B
Value parameters:
f

(accumulator, nextValue) => nextAccumulator On first call of f, accumulator is initial, and nextValue is array[0] If array is empty or only has one item, initial is returned without calling f.

def reduceWithIndex(f: Function3[A, A, Int, A]): A
Value parameters:
f

(accumulator, nextValue, nextIndex) => nextAccumulator On first call of f, accumulator is array[0], and nextValue is array[1]. If array only has one item, array[0] is returned without calling f. Note: throws exception if array is empty.

def reduceWithIndex[B](f: Function3[B, A, Int, B], initial: B): B
Value parameters:
f

(accumulator, nextValue, nextIndex) => nextAccumulator On first call of f, accumulator is initial, and nextValue is array[0] If array is empty or only has one item, initial is returned without calling f.

def reverse(): JsArray[A]

Reverse an array in place. The first array element becomes the last and the last becomes the first.

Reverse an array in place. The first array element becomes the last and the last becomes the first.

def shift(): A

Remove the first element from an array and return that element.

Remove the first element from an array and return that element.

Returns js.undefined if array is empty.

def slice(start: Int, end: Int): JsArray[A]

Return a shallow copy of a portion of an array.

Return a shallow copy of a portion of an array.

def sort(compareFn: Function2[A, A, Int]): JsArray[A]

Sort the elements of an array in place and return the array. The default sort order is lexicographic (not numeric).

Sort the elements of an array in place and return the array. The default sort order is lexicographic (not numeric).

!! The sort is not stable in IE!

If compareFn is not supplied, elements are sorted by converting them to strings and comparing strings in lexicographic ("dictionary" or "telephone book," not numerical) order. For example, "80" comes before "9" in lexicographic order, but in a numeric sort 9 comes before 80.

See also:
def splice(index: Int, deleteCount: Int, items: A*): JsArray[A]

Remove and add new elements at a given index in the array.

Remove and add new elements at a given index in the array.

This method first removes deleteCount elements starting from the index index, then inserts the new elements items at that index.

If index is negative, it is treated as that number of elements starting from the end of the array.

Value parameters:
deleteCount

Number of elements to delete from index

index

Index where to start changes

items

Elements to insert at index

Returns:

An array of the elements that were deleted

def unshift(items: A*): Int

Add one or more elements to the beginning of the array and return the new length of the array.

Add one or more elements to the beginning of the array and return the new length of the array.

def update(index: Int, value: A): Unit

Set the element at the given index.

Set the element at the given index.

Inherited methods

def hasOwnProperty(v: String): Boolean
Inherited from:
Object
def isPrototypeOf(v: Object): Boolean
Inherited from:
Object
def iterator(): Iterator[A]

!! Not supported by IE !!

!! Not supported by IE !!

Inherited from:
JsIterable
def propertyIsEnumerable(v: String): Boolean
Inherited from:
Object
def toLocaleString(): String
Inherited from:
Object
def valueOf(): Any
Inherited from:
Object

Concrete fields

val arr: JsArray[A]
Implicitly added by RichJsArray