- .push(...value)
- .pushSet(...value)
- .pull({ result = false })
- .shift({ result = false })
- .unshift(...value)
- .splice(start, deleteCount, ...items)
- .map(func)
- .sort(func)
- .filter(func)
- .reduce(func)
- .concat(...arrays)
- .unique()
- .chunk(size)
- .flattenMatrix()
- .shuffleArray()
- .intersection(input)
- .XOR(input)
- .difference(input)
- .differenceInsert(input)
Adds one or more values to the end of the target array.
Parameter | Type |
---|---|
value | array |
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").push(4, 5)
//after: {"items": [1, 2, 3, 4, 5]}
Adds one or more values to the target array, ensuring no duplicates are added.
Parameter | Type |
---|---|
value | array |
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").pushSet(2, 4)
//after: {"items": [1, 2, 3, 4]}
Removes and returns the last element of the target array.
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").pull()
//after: {"items": [1, 2]}
//with result option:
const last = DB.get("items").pull({ result: true });
console.log(last) // 3
Removes and returns the first element of the target array.
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").shift()
//after: {"items": [2, 3]}
//with result option:
const first = DB.get("items").shift({ result: true });
console.log(first) // 1
Adds one or more values to the beginning of the target array.
Parameter | Type |
---|---|
value | array |
Example:
//before: {"items": [2, 3]}
DB.get("items").unshift(1)
//after: {"items": [1, 2, 3]}
Modifies the target array by removing or replacing existing elements and/or adding new elements.
Parameter | Type |
---|---|
start | number |
deleteCount | number |
...items | array |
Example:
//before: {"items": [1, 2, 3, 4]}
DB.get("items").splice(1, 2, 5, 6)
//after: {"items": [1, 5, 6, 4]}
Applies the provided function to every element in the target array and updates the array.
Parameter | Type |
---|---|
func | function |
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").map(x => x * 2)
//after: {"items": [2, 4, 6]}
Sorts the target array in place, optionally using the provided function. \
Parameter | Type |
---|---|
func | function |
Example:
//before: {"items": [3, 1, 2]}
DB.get("items").sort()
//after: {"items": [1, 2, 3]}
Filters the target array, keeping elements that satisfy the provided function.
Parameter | Type |
---|---|
func | function |
Example:
//before: {"items": [1, 2, 3, 4]}
DB.get("items").filter(x => x % 2 === 0)
//after: {"items": [2, 4]}
Applies the provided function to reduce the array to a single value and sets the result as the new value.
Parameter | Type |
---|---|
func | function |
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").reduce((acc, val) => acc + val)
//after: {"items": 6}
Concatenates the target array with other arrays.
Parameter | Type |
---|---|
arrays | array |
Example:
//before: {"items": [1, 2]}
DB.get("items").concat([3, 4])
//after: {"items": [1, 2, 3, 4]}
Removes duplicate values from the target array.
Example:
//before: {"items": [1, 1, 2, 2, 3]}
DB.get("items").unique()
//after: {"items": [1, 2, 3]}
Breaks the target array into smaller arrays of the specified size.
Parameter | Type |
---|---|
size | number |
Example:
//before: {"items": [1, 2, 3, 4, 5]}
DB.get("items").chunk(2)
//after: {"items": [[1, 2], [3, 4], [5]]}
Flattens a matrix (an array of arrays) into a single array.
Example:
//before: {"items": [[1, 2], [3, 4]]}
DB.get("items").flattenMatrix()
//after: {"items": [1, 2, 3, 4]}
Shuffles the elements in the target array randomly.
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").shuffleArray()
//after: {"items": [2, 3, 1]} // random order
Returns the intersection of the target array or object and the input.
Parameter | Type |
---|---|
input | array |
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").intersection([2, 3, 4])
//after: {"items": [2, 3]}
Returns the symmetric difference of the target array or object and the input.
Parameter | Type |
---|---|
input | array |
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").XOR([3, 4])
//after: {"items": [1, 2, 4]}
Returns the difference between the target array or object and the input.
Parameter | Type |
---|---|
input | array |
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").difference([2])
//after: {"items": [1, 3]}
Returns the elements from the input that do not exist in the target array or object and sets them as the new value.
Parameter | Type |
---|---|
input | array |
Example:
//before: {"items": [1, 2, 3]}
DB.get("items").differenceInsert([2, 3, 4])
//after: {"items": [4]}