
ctrl+k
Enter a search term above to see results...
Enter a search term above to see results...
Array Helpers provide convenient ways to modify arrays reactively, ensuring that dependent computations are updated when the array changes.
Adds one or more elements to the end of the array.
signal.push(...elements)
Name | Type | Description |
---|---|---|
…elements | any | One or more elements to add to the end of the array |
import { Signal } from '@semantic-ui/reactivity';
const fruits = new Signal(['apple']);fruits.push('banana'); // ['apple', 'banana']fruits.push('orange', 'grape'); // ['apple', 'banana', 'orange', 'grape']
Adds one or more elements to the beginning of the array.
signal.unshift(...elements)
Name | Type | Description |
---|---|---|
…elements | any | One or more elements to add to the beginning of the array |
import { Signal } from '@semantic-ui/reactivity';
const numbers = new Signal([3]);numbers.unshift(1, 2); // [1, 2, 3]
Changes the contents of the array by removing or replacing existing elements and/or adding new elements.
signal.splice(start, deleteCount?, ...items)
Name | Type | Description |
---|---|---|
start | number | The index at which to start changing the array |
deleteCount | number | (Optional) Number of elements to remove |
…items | any | (Optional) Elements to insert |
import { Signal } from '@semantic-ui/reactivity';
const colors = new Signal(['red', 'green', 'blue']);colors.splice(1, 1, 'yellow'); // ['red', 'yellow', 'blue']
Sets the value at a specific index in the array.
signal.setIndex(index, value)
Name | Type | Description |
---|---|---|
index | number | The index at which to set the value |
value | any | The value to set |
import { Signal } from '@semantic-ui/reactivity';
const items = new Signal(['a', 'b', 'c']);items.setIndex(1, 'x'); // ['a', 'x', 'c']
Removes the element at a specific index from the array.
signal.removeIndex(index)
Name | Type | Description |
---|---|---|
index | number | The index of the element to remove |
import { Signal } from '@semantic-ui/reactivity';
const letters = new Signal(['a', 'b', 'c']);letters.removeIndex(1); // ['a', 'c']
Gets the element at a specific index in the array.
signal.getIndex(index)
Name | Type | Description |
---|---|---|
index | number | The index of the element to retrieve |
import { Signal } from '@semantic-ui/reactivity';
const letters = new Signal(['a', 'b', 'c']);const secondLetter = letters.getIndex(1); // 'b'
Filters the array to only include elements that pass the test provided by the callback function.
signal.filter(predicate)
Name | Type | Description |
---|---|---|
predicate | Function | Function to test each element of the array. Takes three arguments: the current element, its index, and the array being processed |
import { Signal } from '@semantic-ui/reactivity';
const numbers = new Signal([1, 2, 3, 4, 5]);numbers.filter(n => n % 2 === 0); // [2, 4]
Transforms each element in the array using the provided mapping function.
signal.map(callback)
Name | Type | Description |
---|---|---|
callback | Function | Function to transform each element. Takes three arguments: the current element, its index, and the array being processed |
import { Signal } from '@semantic-ui/reactivity';
const numbers = new Signal([1, 2, 3]);numbers.map(n => n * 2); // [2, 4, 6]