Struct Array

#[repr(transparent)]
pub struct Array<T = JsValue> { /* private fields */ }

Implementations

impl Array

fn from(val: &JsValue) -> Array

The Array.from() static method creates a new, shallow-copied Array instance from an array-like or iterable object.

MDN documentation

impl Array

fn from_iterable<I>(val: &I) -> Result<Array<I::Item>, JsValue>
where
    I: Iterable + ErasableGenericBorrow<JsValue>,
    Array<I::Item>: ErasableGenericOwn<Array<JsValue>>,

The Array.from() static method creates a new, shallow-copied Array instance from an array-like or iterable object.

MDN documentation

impl Array

fn of1(a: &JsValue) -> Array

MDN documentation

impl Array

fn from_async<I>(val: &I) -> Result<Promise<Array<I::Item>>, JsValue>
where
    I: AsyncIterable + ErasableGenericBorrow<JsValue>,
    Promise<Array<I::Item>>: ErasableGenericOwn<Promise<Array<JsValue>>>,

The Array.fromAsync() static method creates a new, shallow-copied Array instance from an async iterable, iterable or array-like object.

MDN documentation

impl Array

fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array

MDN documentation

impl Array

fn from_async_map<'a, I, R>(val: &I, map: &ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>) -> Result<Promise<Array<R::Resolution>>, JsValue>
where
    I: AsyncIterable + ErasableGenericBorrow<JsValue>,
    R: Promising,
    ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>: ErasableGenericBorrow<ScopedClosure<'static, dyn FnMut(JsValue, u32) -> Result<JsValue, JsError>>>,
    Promise<Array<R::Resolution>>: ErasableGenericOwn<Promise<Array<JsValue>>>,

The Array.fromAsync() static method with a map function creates a new, shallow-copied Array instance from an async iterable, iterable or array-like object, applying the map function to each value.

MDN documentation

impl Array

fn new() -> Array

Creates a new empty array.

MDN documentation

impl Array

fn is_array(value: &JsValue) -> bool

The Array.isArray() method determines whether the passed value is an Array.

MDN documentation

impl Array

fn of2(a: &JsValue, b: &JsValue) -> Array

MDN documentation

impl Array

fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array

MDN documentation

impl Array

fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array

MDN documentation

impl Array

fn new_with_length(len: u32) -> Array

Creates a new array with the specified length (elements are initialized to undefined).

MDN documentation

impl<T> Array<T>

fn get(&self, index: u32) -> T
where
    T: ErasableGenericOwn<JsValue>,

Retrieves the element at the index (returns undefined if the index is out of range).

MDN documentation

impl<T> Array<T>

fn try_to_sorted_by(&self, compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>) -> Result<Array<T>, JsValue>
where
    dyn FnMut(T, T) -> Result<i32, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue) -> Result<i32, JsError>>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The toSorted() method with a custom compare function. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn last_index_of(&self, value: &T, from_index: i32) -> i32
where
    T: ErasableGenericBorrow<JsValue>,

The lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.

MDN documentation

impl<T> Array<T>

fn set(&self, index: u32, value: T)
where
    T: ErasableGenericOwn<JsValue>,

Sets the element at the index (auto-enlarges the array if the index is out of range).

impl<T> Array<T>

fn to_vec(&self) -> Vec<T>
where
    Vec<T>: ErasableGenericOwn<Vec<JsValue>>,

Converts the Array into a Vector.

impl<T> Array<T>

fn with(&self, index: u32, value: &T) -> Array<T>
where
    T: ErasableGenericBorrow<JsValue>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The with() method returns a new array with the element at the given index replaced with the given value, without modifying the original array.

MDN documentation

impl<T> Array<T>

fn entries(&self) -> Iterator<T>
where
    Iterator<T>: ErasableGenericOwn<Iterator<JsValue>>,

The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.

MDN documentation

impl<T> Array<T>

fn pop_checked(&self) -> Option<T>
where
    Option<T>: ErasableGenericOwn<Option<JsValue>>,

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

MDN documentation

impl<T> Array<T>

fn concat_many<U>(&self, array: &[Array<U>]) -> Array<T>
where
    U: Upcast<T>,
    [Array<U>]: ErasableGenericBorrow<[Array<JsValue>]>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

MDN documentation

impl<T> Array<T>

fn every(&self, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> bool
where
    dyn FnMut(T, u32, Array<T>) -> bool: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32, Array<JsValue>) -> bool>,

The every() method tests whether all elements in the array pass the test implemented by the provided function.

Note: Consider using Array::try_every if the predicate might throw an error.

MDN documentation

impl<T> Array<T>

fn reduce(&self, predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue, initial_value: &JsValue) -> JsValue
where
    dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue: ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue, u32, Array<JsValue>) -> JsValue>,

The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.

MDN documentation

impl<T> Array<T>

fn fill(&self, value: &T, start: u32, end: u32) -> Array<T>
where
    T: ErasableGenericBorrow<JsValue>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The fill() method fills all the elements of an array from a start index to an end index with a static value. The end index is not included.

MDN documentation

impl<T> Array<T>

fn filter(&self, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> Array<T>
where
    dyn FnMut(T, u32, Array<T>) -> bool: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32, Array<JsValue>) -> bool>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The filter() method creates a new array with all elements that pass the test implemented by the provided function.

Note: Consider using Array::try_filter if the predicate might throw an error.

MDN documentation

impl<T> Array<T>

fn try_reduce_right<A>(&self, predicate: &mut dyn FnMut(JsValue, T, u32) -> Result<A, JsError>, initial_value: &A) -> Result<A, JsValue>
where
    dyn FnMut(JsValue, T, u32) -> Result<A, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue, u32) -> Result<JsValue, JsError>>,
    A: ErasableGenericBorrow<JsValue> + ErasableGenericOwn<JsValue>,

The reduceRight() method applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn find(&self, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T
where
    dyn FnMut(T, u32, Array<T>) -> bool: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32, Array<JsValue>) -> bool>,
    T: ErasableGenericOwn<JsValue>,

The find() method returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.

MDN documentation

impl<T> Array<T>

fn shift_checked(&self) -> Option<T>
where
    Option<T>: ErasableGenericOwn<Option<JsValue>>,

The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.

MDN documentation

impl<T> Array<T>

fn try_find_index(&self, predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>) -> Result<i32, JsValue>
where
    dyn FnMut(T, u32) -> Result<bool, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Result<bool, JsError>>,

The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise -1 is returned. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn splice_many(&self, start: u32, delete_count: u32, items: &[T]) -> Array<T>
where
    [T]: ErasableGenericBorrow<[JsValue]>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The splice() method changes the contents of an array by removing existing elements and/or adding new elements.

MDN documentation

impl<T> Array<T>

fn try_for_each(&self, callback: &mut dyn FnMut(T, u32) -> Result<(), JsError>) -> Result<(), JsValue>
where
    dyn FnMut(T, u32) -> Result<(), JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Result<(), JsError>>,

The forEach() method executes a provided function once for each array element. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn new_with_length_typed(len: u32) -> Array<T>
where
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

Creates a new array with the specified length (elements are initialized to undefined).

MDN documentation

impl<T> Array<T>

fn to_sorted(&self) -> Array<T>
where
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The toSorted() method returns a new array with the elements sorted in ascending order, without modifying the original array.

MDN documentation

impl<T> Array<T>

fn to_sorted_by(&self, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>
where
    dyn FnMut(T, T) -> i32: ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue) -> i32>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The toSorted() method with a custom compare function.

Note: Consider using Array::try_to_sorted_by if the predicate might throw an error.

MDN documentation

impl<T> Array<T>

fn get_unchecked(&self, index: u32) -> T
where
    T: ErasableGenericOwn<JsValue>,

Retrieves the element at the index (returns undefined if the index is out of range).

MDN documentation

impl<T> Array<T>

fn to_spliced(&self, start: u32, delete_count: u32, items: &[T]) -> Array<T>
where
    [T]: ErasableGenericBorrow<[JsValue]>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The toSpliced() method returns a new array with some elements removed and/or replaced at a given index, without modifying the original array.

MDN documentation

impl<T> Array<T>

fn length(&self) -> u32

The length property of an object which is an instance of type Array sets or returns the number of elements in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.

MDN documentation

impl<T> Array<T>

fn set_ref(&self, index: u32, value: &T)
where
    T: ErasableGenericBorrow<JsValue>,

Sets the element at the index (auto-enlarges the array if the index is out of range).

impl<T> Array<T>

fn unshift(&self, value: &T) -> u32
where
    T: ErasableGenericBorrow<JsValue>,

The unshift() method adds one element to the beginning of an array and returns the new length of the array.

MDN documentation

impl<T> Array<T>

fn try_map<U>(&self, predicate: &mut dyn FnMut(T, u32) -> Result<U, JsError>) -> Result<Array<U>, JsValue>
where
    dyn FnMut(T, u32) -> Result<U, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Result<JsValue, JsError>>,
    Array<U>: ErasableGenericOwn<Array<JsValue>>,

map() calls a provided callback function once for each element in an array, in order, and constructs a new array from the results. callback is invoked only for indexes of the array which have assigned values, including undefined. It is not called for missing elements of the array (that is, indexes that have never been set, which have been deleted or which have never been assigned a value). (Fallible variation)

MDN documentation

impl<T> Array<T>

fn copy_within(&self, target: i32, start: i32, end: i32) -> Array<T>
where
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The copyWithin() method shallow copies part of an array to another location in the same array and returns it, without modifying its size.

MDN documentation

impl<T> Array<T>

fn pop(&self) -> T
where
    T: ErasableGenericOwn<JsValue>,

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

Note: Consider using Array::pop_checked for handling empty arrays.

MDN documentation

impl<T> Array<T>

fn push(&self, value: &T) -> u32
where
    T: ErasableGenericBorrow<JsValue>,

The push() method adds one element to the end of an array and returns the new length of the array.

MDN documentation

impl<T> Array<T>

fn values(&self) -> Iterator<T>
where
    Iterator<T>: ErasableGenericOwn<Iterator<JsValue>>,

The values() method returns a new Array Iterator object that contains the values for each index in the array.

MDN documentation

impl<T> Array<T>

fn try_reduce<A>(&self, predicate: &mut dyn FnMut(A, T, u32) -> Result<A, JsError>, initial_value: &A) -> Result<A, JsValue>
where
    dyn FnMut(A, T, u32) -> Result<A, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue, u32) -> Result<JsValue, JsError>>,
    A: ErasableGenericBorrow<JsValue> + ErasableGenericOwn<JsValue>,

The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn reverse(&self) -> Array<T>
where
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The reverse() method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.

MDN documentation

impl<T> Array<T>

fn try_find(&self, predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>) -> Result<Option<T>, JsValue>
where
    dyn FnMut(T, u32) -> Result<bool, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Result<bool, JsError>>,
    Option<T>: ErasableGenericOwn<Option<JsValue>>,

The find() method returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn shift(&self) -> T
where
    T: ErasableGenericOwn<JsValue>,

The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.

Note: Consider using Array::shift_checked for handling empty arrays.

MDN documentation

impl<T> Array<T>

fn find_index(&self, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> i32
where
    dyn FnMut(T, u32, Array<T>) -> bool: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32, Array<JsValue>) -> bool>,

The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise -1 is returned.

Note: Consider using Array::try_find_index if the predicate might throw an error.

MDN documentation

impl<T> Array<T>

fn slice(&self, start: u32, end: u32) -> Array<T>
where
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included). The original array will not be modified.

MDN documentation

impl<T> Array<T>

fn find_last(&self, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T
where
    dyn FnMut(T, u32, Array<T>) -> bool: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32, Array<JsValue>) -> bool>,
    T: ErasableGenericOwn<JsValue>,

The findLast() method of Array instances iterates the array in reverse order and returns the value of the first element that satisfies the provided testing function. If no elements satisfy the testing function, undefined is returned.

MDN documentation

impl<T> Array<T>

fn try_some(&self, predicate: &mut dyn FnMut(T) -> Result<bool, JsError>) -> Result<bool, JsValue>
where
    dyn FnMut(T) -> Result<bool, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue) -> Result<bool, JsError>>,

The some() method tests whether at least one element in the array passes the test implemented by the provided function. (Fallible variation) Note: This method returns false for any condition put on an empty array. MDN documentation

impl<T> Array<T>

fn try_find_last_index(&self, predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>) -> Result<i32, JsValue>
where
    dyn FnMut(T, u32) -> Result<bool, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Result<bool, JsError>>,

The findLastIndex() method of Array instances iterates the array in reverse order and returns the index of the first element that satisfies the provided testing function. If no elements satisfy the testing function, -1 is returned. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn try_sort_by(&self, compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>) -> Result<Array<T>, JsValue>
where
    dyn FnMut(T, T) -> Result<i32, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue) -> Result<i32, JsError>>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The sort() method with a custom compare function. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn try_flat_map<U>(&self, callback: &mut dyn FnMut(T, u32) -> Vec<U>) -> Result<Array<U>, JsValue>
where
    dyn FnMut(T, u32) -> Vec<U>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Vec<JsValue>>,
    Array<U>: ErasableGenericOwn<Array<JsValue>>,

The flatMap() method first maps each element using a mapping function, then flattens the result into a new array.

MDN documentation

impl<T> Array<T>

fn new_typed() -> Array<T>
where
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

Creates a new empty array.

MDN documentation

impl<T> Array<T>

fn to_locale_string(&self, locales: &JsValue, options: &JsValue) -> JsString

The toLocaleString() method returns a string representing the elements of the array. The elements are converted to Strings using their toLocaleString methods and these Strings are separated by a locale-specific String (such as a comma ",").

MDN documentation

impl<T> Array<T>

fn includes(&self, value: &T, from_index: i32) -> bool
where
    T: ErasableGenericBorrow<JsValue>,

The includes() method determines whether an array includes a certain element, returning true or false as appropriate.

MDN documentation

impl<T> Array<T>

fn at(&self, index: i32) -> T
where
    T: ErasableGenericOwn<JsValue>,

Retrieves the element at the index, counting from the end if negative (returns undefined if the index is out of range).

MDN documentation

impl<T> Array<T>

fn join(&self, delimiter: &str) -> JsString

The join() method joins all elements of an array (or an array-like object) into a string and returns this string.

MDN documentation

impl<T> Array<T>

fn get_checked(&self, index: u32) -> Option<T>
where
    Option<T>: ErasableGenericOwn<Option<JsValue>>,

Retrieves the element at the index (returns None if the index is out of range, or if the element is explicitly undefined).

impl<T> Array<T>

fn to_string(&self) -> JsString

The toString() method returns a string representing the specified array and its elements.

MDN documentation

impl<T> Array<T>

fn set_length(&self, value: u32)

Sets the length of the array.

If it is set to less than the current length of the array, it will shrink the array.

If it is set to more than the current length of the array, it will increase the length of the array, filling the new space with empty slots.

MDN documentation

impl<T> Array<T>

fn delete(&self, index: u32)

Deletes the element at the index (does nothing if the index is out of range).

The element at the index is set to undefined.

This does not resize the array, the array will still be the same length.

impl<T> Array<T>

fn map<U>(&self, predicate: &mut dyn FnMut(T, u32, Array<T>) -> U) -> Array<U>
where
    dyn FnMut(T, u32, Array<T>) -> U: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32, Array<JsValue>) -> JsValue>,
    Array<U>: ErasableGenericOwn<Array<JsValue>>,

map() calls a provided callback function once for each element in an array, in order, and constructs a new array from the results. callback is invoked only for indexes of the array which have assigned values, including undefined. It is not called for missing elements of the array (that is, indexes that have never been set, which have been deleted or which have never been assigned a value).

Note: Consider using Array::try_map for safer fallible handling.

MDN documentation

impl<T> Array<T>

fn unshift_many(&self, values: &[T]) -> u32
where
    [T]: ErasableGenericBorrow<[JsValue]>,

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

MDN documentation

impl<T> Array<T>

fn of(values: &[T]) -> Array<T>
where
    [T]: ErasableGenericBorrow<[JsValue]>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The Array.of() method creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments.

Note: For type inference use Array::<T>::of(&[T]).

The difference between Array.of() and the Array constructor is in the handling of integer arguments: Array.of(7) creates an array with a single element, 7, whereas Array(7) creates an empty array with a length property of 7 (Note: this implies an array of 7 empty slots, not slots with actual undefined values).

MDN documentation

impl<T> Array<T>

fn keys(&self) -> Iterator<T>
where
    Iterator<T>: ErasableGenericOwn<Iterator<JsValue>>,

The keys() method returns a new Array Iterator object that contains the keys for each index in the array.

MDN documentation

impl<T> Array<T>

fn concat<U>(&self, array: &Array<U>) -> Array<T>
where
    U: Upcast<T>,
    Array<U>: ErasableGenericBorrow<Array<JsValue>>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

MDN documentation

impl<T> Array<T>

fn push_many(&self, values: &[T]) -> u32
where
    [T]: ErasableGenericBorrow<[JsValue]>,

The push() method adds one or more elements to the end of an array and returns the new length of the array.

MDN documentation

impl<T> Array<T>

fn try_every(&self, predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>) -> Result<bool, JsValue>
where
    dyn FnMut(T, u32) -> Result<bool, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Result<bool, JsError>>,

The every() method tests whether all elements in the array pass the test implemented by the provided function. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn reduce_right(&self, predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue, initial_value: &JsValue) -> JsValue
where
    dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue: ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue, u32, Array<JsValue>) -> JsValue>,

The reduceRight() method applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.

MDN documentation

impl<T> Array<T>

fn try_filter(&self, predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>) -> Result<Array<T>, JsValue>
where
    dyn FnMut(T, u32) -> Result<bool, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Result<bool, JsError>>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The filter() method creates a new array with all elements that pass the test implemented by the provided function. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn slice_from(&self, start: u32) -> Array<T>
where
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The slice() method returns a shallow copy of a portion of an array into a new array object selected from the given index to the end. The original array will not be modified.

MDN documentation

impl<T> Array<T>

fn try_find_last(&self, predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>) -> Result<Option<T>, JsValue>
where
    dyn FnMut(T, u32) -> Result<bool, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Result<bool, JsError>>,
    Option<T>: ErasableGenericOwn<Option<JsValue>>,

The findLast() method of Array instances iterates the array in reverse order and returns the value of the first element that satisfies the provided testing function. If no elements satisfy the testing function, undefined is returned. (Fallible variation)

MDN documentation

impl<T> Array<T>

fn some(&self, predicate: &mut dyn FnMut(T) -> bool) -> bool
where
    dyn FnMut(T) -> bool: ErasableGenericBorrowMut<dyn FnMut(JsValue) -> bool>,

The some() method tests whether at least one element in the array passes the test implemented by the provided function. Note: This method returns false for any condition put on an empty array.

Note: Consider using Array::try_some if the predicate might throw an error.

MDN documentation

impl<T> Array<T>

fn find_last_index(&self, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> i32
where
    dyn FnMut(T, u32, Array<T>) -> bool: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32, Array<JsValue>) -> bool>,

The findLastIndex() method of Array instances iterates the array in reverse order and returns the index of the first element that satisfies the provided testing function. If no elements satisfy the testing function, -1 is returned.

Note: Consider using Array::try_find_last_index if the predicate might throw an error.

MDN documentation

impl<T> Array<T>

fn sort(&self) -> Array<T>
where
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The sort() method sorts the elements of an array in place and returns the array. The sort is not necessarily stable. The default sort order is according to string Unicode code points.

The time and space complexity of the sort cannot be guaranteed as it is implementation dependent.

MDN documentation

impl<T> Array<T>

fn flat(&self, depth: i32) -> Array<JsValue>

The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

MDN documentation

impl<T> Array<T>

fn sort_by(&self, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>
where
    dyn FnMut(T, T) -> i32: ErasableGenericBorrowMut<dyn FnMut(JsValue, JsValue) -> i32>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The sort() method with a custom compare function.

Note: Consider using Array::try_sort_by if the predicate might throw an error.

MDN documentation

impl<T> Array<T>

fn flat_map<U>(&self, callback: &mut dyn FnMut(T, u32, Array<T>) -> Vec<U>) -> Array<U>
where
    dyn FnMut(T, u32, Array<T>) -> Vec<U>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32, Array<JsValue>) -> Vec<JsValue>>,
    Array<U>: ErasableGenericOwn<Array<JsValue>>,

The flatMap() method first maps each element using a mapping function, then flattens the result into a new array.

Note: Consider using Array::try_flat_map for safer fallible handling.

MDN documentation

impl<T> Array<T>

fn splice(&self, start: u32, delete_count: u32, item: &T) -> Array<T>
where
    T: ErasableGenericBorrow<JsValue>,
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The splice() method changes the contents of an array by removing existing elements and/or adding new elements.

MDN documentation

impl<T> Array<T>

fn to_reversed(&self) -> Array<T>
where
    Array<T>: ErasableGenericOwn<Array<JsValue>>,

The toReversed() method returns a new array with the elements in reversed order, without modifying the original array.

MDN documentation

impl<T> Array<T>

fn index_of(&self, value: &T, from_index: i32) -> i32
where
    T: ErasableGenericBorrow<JsValue>,

The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

MDN documentation

impl<T> Array<T> where T: JsGeneric,

fn entries_typed(&self) -> Iterator<ArrayTuple<(Number, T)>>
where
    Iterator<ArrayTuple<(Number, T)>>: ErasableGenericOwn<Iterator<ArrayTuple<(Number, JsValue)>>>,

The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.

MDN documentation

impl<T> Array<T> where T: JsGeneric,

fn for_each(&self, callback: &mut dyn FnMut(T, u32, Array<T>))
where
    dyn FnMut(T, u32, Array<T>): ErasableGenericBorrowMut<dyn FnMut(JsValue, u32, Array<JsValue>)>,

The forEach() method executes a provided function once for each array element.

Note: Consider using Array::try_for_each if the callback might throw an error.

MDN documentation

impl<T: JsGeneric> Array<T>

fn iter(&self) -> ArrayIter<'_, T>

Returns an iterator over the values of the JS array.

impl<T: JsGeneric> Array<T>

fn from_iter_typed<A, I>(iter: I) -> Array<T>
where
    A: IntoJsGeneric<JsCanon = T>,
    I: IntoIterator<Item = A>,

Collect an iterator into a typed Array<T>, projecting each item through its canonical JsGeneric via IntoJsGeneric.

This is the typed counterpart to the stable impl FromIterator<A> for Array where A: AsRef<JsValue>, which always produces an erased Array<JsValue>. Use from_iter_typed when you want the element type inferred from the iterator item:

use js_sys::{Array, Number};

let arr = Array::from_iter_typed((0..10).map(Number::from));
// arr: Array<Number>

Reference iteration (Item = &U) is supported transparently via the &U: IntoJsGeneric blanket in wasm-bindgen core.

fn extend_typed<A, I>(&mut self, iter: I)
where
    A: IntoJsGeneric<JsCanon = T>,
    I: IntoIterator<Item = A>,

Extend a typed Array<T> with an iterator of items convertible to T via IntoJsGeneric. Companion to Array::from_iter_typed.

impl<U> Array<U>

fn from_iterable_map<I>(val: &I, map: &mut dyn FnMut(I::Item, u32) -> Result<U, JsError>) -> Result<Array<U>, JsValue>
where
    I: Iterable + ErasableGenericBorrow<JsValue>,
    dyn FnMut(I::Item, u32) -> Result<U, JsError>: ErasableGenericBorrowMut<dyn FnMut(JsValue, u32) -> Result<JsValue, JsError>>,
    Array<U>: ErasableGenericOwn<Array<JsValue>>,

The Array.from() static method with a map function creates a new, shallow-copied Array instance from an array-like or iterable object, applying the map function to each value.

MDN documentation

Trait Implementations

impl Default for Array<JsValue>

fn default() -> Self

impl From<JsValue> for Array

fn from(obj: JsValue) -> Self

impl From<RegExpMatchArray> for Array

fn from(obj: RegExpMatchArray) -> Array

impl UpcastFrom<RegExpMatchArray> for Array

impl<A> Extend<A> for Array where A: AsRef<JsValue>,

fn extend<I>(&mut self, iter: I)
where
    I: IntoIterator<Item = A>,

impl<A> FromIterator<A> for Array where A: AsRef<JsValue>,

fn from_iter<I>(iter: I) -> Array
where
    I: IntoIterator<Item = A>,

impl<T> AsRef<Array<T>> for Array<T>

fn as_ref(&self) -> &Array<T>

impl<T> AsRef<JsValue> for Array<T>

fn as_ref(&self) -> &JsValue

impl<T> AsRef<Object> for Array<T>

fn as_ref(&self) -> &Object

impl<T> Deref for Array<T>

type Target = Object;
fn deref(&self) -> &Object

impl<T> ErasableGeneric for Array<T>

type Repr = JsValue;

impl<T> FromWasmAbi for Array<T>

type Abi = <JsValue as FromWasmAbi>::Abi;
unsafe fn from_abi(js: Self::Abi) -> Self

impl<T> IntoJsGeneric for Array<T> where Array<T>: JsGeneric,

type JsCanon = Array<T>;
fn to_js(self) -> Array<T>

impl<T> IntoWasmAbi for Array<T>

type Abi = <JsValue as IntoWasmAbi>::Abi;
fn into_abi(self) -> Self::Abi

impl<T> Iterable for Array<T>

type Item = T;

impl<T> JsCast for Array<T>

fn instanceof(val: &JsValue) -> bool
fn is_type_of(val: &JsValue) -> bool
fn unchecked_from_js(val: JsValue) -> Self
fn unchecked_from_js_ref(val: &JsValue) -> &Self

impl<T> LongRefFromWasmAbi for Array<T>

type Abi = <JsValue as LongRefFromWasmAbi>::Abi;
type Anchor = Array<T>;
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

impl<T> OptionFromWasmAbi for Array<T>

fn is_none(abi: &Self::Abi) -> bool

impl<T> OptionIntoWasmAbi for Array<T>

fn none() -> Self::Abi

impl<T> Promising for Array<T>

type Resolution = Array<T>;

impl<T> RefFromWasmAbi for Array<T>

type Abi = <JsValue as RefFromWasmAbi>::Abi;
type Anchor = ManuallyDrop<Array<T>>;
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

impl<T> WasmDescribe for Array<T>

fn describe()

impl<T, __UpcastTarget0> UpcastFrom<Array<T>> for Array<__UpcastTarget0> where __UpcastTarget0: UpcastFrom<T>,

impl<T1, T2, T3, T4, T5, T6, T7, T8, Target> UpcastFrom<ArrayTuple<(T1, T2, T3, T4, T5, T6, T7, T8)>> for Array<Target> where Target: UpcastFrom<T1> + UpcastFrom<T2> + UpcastFrom<T3> + UpcastFrom<T4> + UpcastFrom<T5> + UpcastFrom<T6> + UpcastFrom<T7> + UpcastFrom<T8>,

impl<T1, T2, T3, T4, T5, T6, T7, Target> UpcastFrom<ArrayTuple<(T1, T2, T3, T4, T5, T6, T7)>> for Array<Target> where Target: UpcastFrom<T1> + UpcastFrom<T2> + UpcastFrom<T3> + UpcastFrom<T4> + UpcastFrom<T5> + UpcastFrom<T6> + UpcastFrom<T7>,

impl<T1, T2, T3, T4, T5, T6, Target> UpcastFrom<ArrayTuple<(T1, T2, T3, T4, T5, T6)>> for Array<Target> where Target: UpcastFrom<T1> + UpcastFrom<T2> + UpcastFrom<T3> + UpcastFrom<T4> + UpcastFrom<T5> + UpcastFrom<T6>,

impl<T1, T2, T3, T4, T5, Target> UpcastFrom<ArrayTuple<(T1, T2, T3, T4, T5)>> for Array<Target> where Target: UpcastFrom<T1> + UpcastFrom<T2> + UpcastFrom<T3> + UpcastFrom<T4> + UpcastFrom<T5>,

impl<T1, T2, T3, T4, Target> UpcastFrom<ArrayTuple<(T1, T2, T3, T4)>> for Array<Target> where Target: UpcastFrom<T1> + UpcastFrom<T2> + UpcastFrom<T3> + UpcastFrom<T4>,

impl<T1, T2, T3, Target> UpcastFrom<ArrayTuple<(T1, T2, T3)>> for Array<Target> where Target: UpcastFrom<T1> + UpcastFrom<T2> + UpcastFrom<T3>,

impl<T1, T2, Target> UpcastFrom<ArrayTuple<(T1, T2)>> for Array<Target> where Target: UpcastFrom<T1> + UpcastFrom<T2>,

impl<T1, Target> UpcastFrom<ArrayTuple<(T1,)>> for Array<Target> where Target: UpcastFrom<T1>,

impl<T: Clone> Clone for Array<T>

fn clone(&self) -> Self

impl<T: Debug> Debug for Array<T>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<T: Eq> Eq for Array<T>

impl<T: JsGeneric> IntoIterator for Array<T>

type Item = T;
type IntoIter = ArrayIntoIter<T>;
fn into_iter(self) -> Self::IntoIter

impl<T: PartialEq> PartialEq for Array<T>

fn eq(&self, other: &Self) -> bool

impl<T: PartialEq> StructuralPartialEq for Array<T>

Auto Trait Implementations

impl<T> Freeze for Array<T> where PhantomData<(T,)>: Freeze,

impl<T> RefUnwindSafe for Array<T> where PhantomData<(T,)>: RefUnwindSafe,

impl<T> Send for Array<T> where PhantomData<(T,)>: Send,

impl<T> Sync for Array<T> where PhantomData<(T,)>: Sync,

impl<T> Unpin for Array<T> where PhantomData<(T,)>: Unpin,

impl<T> UnsafeUnpin for Array<T> where PhantomData<(T,)>: UnsafeUnpin,

impl<T> UnwindSafe for Array<T> where PhantomData<(T,)>: UnwindSafe,

Blanket Implementations

impl<P, T> Receiver for Array<T> where P: Deref<Target = T> + ?Sized, T: ?Sized,

impl<S, T> Upcast<T> for Array<T> where T: UpcastFrom<S> + ?Sized, S: ?Sized,

impl<T> Any for Array<T> where T: 'static + ?Sized,

impl<T> Borrow<T> for Array<T> where T: ?Sized,

impl<T> BorrowMut<T> for Array<T> where T: ?Sized,

impl<T> CloneToUninit for Array<T> where T: Clone,

impl<T> From<T> for Array<T>

impl<T> JsGeneric for Array<T> where T: ErasableGeneric<Repr = JsValue> + UpcastFrom<T> + Upcast<JsValue> + JsCast + 'static,

impl<T> ReturnWasmAbi for Array<T> where T: IntoWasmAbi,

impl<T> ToOwned for Array<T> where T: Clone,

impl<T> TryFromJsValue for Array<T> where T: JsCast,

impl<T> VectorFromWasmAbi for Array<T> where T: ErasableGeneric<Repr = JsValue> + WasmDescribe,

impl<T> VectorIntoWasmAbi for Array<T> where T: ErasableGeneric<Repr = JsValue> + WasmDescribe,

impl<T> VectorRefIntoWasmAbi for Array<T> where &'a T: for<'a> Into<JsValue>,

impl<T, U> Into<U> for Array<T> where U: From<T>,

impl<T, U> TryFrom<U> for Array<T> where U: Into<T>,

impl<T, U> TryInto<U> for Array<T> where U: TryFrom<T>,