Creates new writable array signal initialized to the given elements.
Optional
elements: T[]The initial elements to copy into the array signal. Defaults to empty array.
Optional signal options.
A readonly signal wrapping this signal.
Copies a section of the array identified by start and end to the same array starting at position target.
The target index to copy the section to. If negative then it is treated as length+target where length is the length of the array.
The start index of the section to copy. If negative then it is treated as length+start.
Optional
end: numberOptional end index (exclusive) of the section to copy. If not specified, length of the array is used as end. If end is negative, it is treated as length+end.
Changes all array elements from start
to end
index to a static value
.
The value to fill array section with.
Optional
start: numberOptional index to start filling the array at. Defaults to 0. If start is negative, it is treated as length+start.
Optional
end: numberOptional index to stop filling the array at. Defaults to length. If end is negative, it is treated as length+end.
Returns the index of the first element in the array where predicate is true, and -1 otherwise.
Called once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.
Optional
thisArg: unknownOptional object to which the this
keyword can refer in the predicate function. Defaults to undefined
.
The index of the first found element or -1 if none.
Calls the given callback function on each element of the array to map the array element to something different. Then flattens the result into a new array. This is identical to a map followed by flat with depth 1.
A function that accepts up to three arguments (value, index, array). Called one time for each element in the array. Must return the mapped value.
Optional
thisArg: ThisOptional object to which the this
keyword can refer in the callback function. Defaults to undefined
.
New array with mapped and flattened valued.
Performs the specified action for each element in the array.
A function that accepts up to three arguments (value, index and the array itself). Called one time for each element in the array.
Optional
thisArg: unknownOptional object to which the this
keyword can refer in the callback function. Defaults to undefined
.
Returns the current signal value version. This version is incremented every time the signal value has really changed. The version starts by 0 and
wraps to Number.MIN_SAFE_INTEGER
when Number.MAX_SAFE_INTEGER
is reached, allowing unique versions for eighteen quadrillion signal updates.
The current signal version.
Determines whether an array includes a certain element, returning true or false as appropriate.
The element to search for.
Optional
fromIndex: numberOptional position in this array at which to begin searching. Defaults to 0.
True if array includes the element, false if not.
Returns the index of the first occurrence of an element in the array.
The element to locate in the array.
The array index at which to begin the search. If omitted, the search starts at index 0.
The index of the first occurrence of the given element, or -1 if not found.
Checks if signal value is still valid. When signal has no dependencies then this method can always return true. If signal has dependencies then it must check if any dependency has changed or became invalid. If yes, then this method must return false and the signal will be re-validated by calling (). If all dependency are valid/unchanged then this method must return true to indicate that the signal value is still valid.
True if signal value is valid, false if it must be re-validated.
Adds all the elements of the array separated by the specified separator string.
Optional
separator: stringA string used to separate one element of an array from the next in the resulting string. If omitted, the array elements are separated with a comma.
The joined string.
Returns the index of the last occurrence of an element in the array.
The element to locate in the array.
The array index at which to begin the search. If omitted, the search starts at the last index in the array.
The index of the last occurrence of the given element, or -1 if not found.
Calls a defined callback function on each element of the array and returns an array that contains the results.
A function that accepts up to three arguments (value, index and the array itself) and returns the mapped value for the array element. Called one time for each element in the array.
Optional
thisArg: unknownOptional object to which the this
keyword can refer in the callback function. Defaults to undefined
.
A new array with the mapped elements.
Returns a section of the array.
Optional
start: numberThe beginning of the specified portion of the array.
Optional
end: numberOptional end of the specified portion of the array. This is exclusive of the element at the index 'end'. Defaults to the array length if not specified.
The sliced section of the array.
Determines whether the specified callback function returns true for any element of the array.
A function that accepts up to three arguments (value, index and the array itself). Called for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.
Optional
thisArg: unknownOptional object to which the this
keyword can refer in the predicate function. Defaults to undefined
.
True if at least one element satisfies the specified test, false if none does.
Sorts an array in place. This method mutates the array and returns a reference to the same array. Does nothing if element has less than two elements.
Optional
compareFn: (a: T, b: T) => numberFunction used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they are equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
Removes elements from the array and, if necessary, inserts new elements in their place, returning the deleted elements.
The zero-based location in the array from which to start removing elements.
Optional number of elements to remove. Defaults to 0.
Elements to insert into the array in place of the deleted elements.
An array containing the elements that were deleted.
Protected
unwatchCalled when () returned false and the current value of this signal is needed. Must compute/fetch and cache the new value so the next call to () returns a valid value. When signal has no dependencies and () is implemented to always return true then this method can stay empty as it has nothing to validate/update.
Protected
watchStatic
fromCreates a writable array signal from an array-like object.
An array-like object to convert to an array signal.
Optional
options: BaseSignalOptions<T>The created writable array signal.
A writable signal for arrays. Provides pretty much all common array functions while automatically tracking changes.