A dead simple helper for modifying arrays in Svelte, and making the code more readable.
This library only contains the array methods that mutate the array.
npm install svelte-array-helper
// Import single static methods
import { push, pop, splice } from 'svelte-array-helper'
// Import class
import ArrayHelper from 'svelte-array-helper'
let arrayHelper = new ArrayHelper // <- Instaciate it
import { push } from 'svelte-array-helper'
let list = [0,1,2,3]
function addToList(itemToAdd) {
list = push(list, itemToAdd)
}
Note
All methods will return the modified array
push(array, value)
push(array)
splice(array, 0, 1, 'item1', 'item2' etc..)
copyWithin(array, ...arguments)
fill(array, ...arguments)
reverse(array)
sort(array, ...arguments)