Copies a sequence of elements to another position in the given array.
import { copyWithin } from '@dojo/framework/shim/array';
var array = [0, 1, 2, 3];
var offSet = 1; // the index where it should begin copying to
var start = 0; // the index where it should begin copying from
var end = 3; // the index where it should end copying from
copyWithin(array, offSet, start, end);
array[0] === 0; // true
array[1] === 0; // true
array[2] === 1; // true
array[3] === 2; // true
Creates an Array
from an array-like object or a string. Array-like. Object being an object that has a length property and is indexible through []
.
import { from } from '@dojo/framework/shim/array';
var nodeList = document.getElementsByTagName('a');
var array = from(nodeList);
array instanceof Array; // true
Fills some or all elements of an array with a given value.
import { fill } from '@dojo/framework/shim/array';
var array = [0, 1, 2, 3];
var start = 1; // the starting index to fill
var end = 4; // the ending index (exclusive) to stop filling
fill(array, 4, start, end);
array[0] === 0; // true
array[1] === 4; // true
array[2] === 4; // true
array[3] === 4; // true
Returns the first value in the array satisfying a given function.
import { find } from '@dojo/framework/shim/array';
var array = [5, 10, 8, 1];
var result = find(array, (elm, index, array) => {
return elm % 2 === 0;
});
result === 10; // true
Returns the first index in the array whose value satisfies a given function.
import { findIndex } from '@dojo/framework/shim/array';
var array = [5, 10, 8, 1];
var result = findIndex(array, (elm, index, array) => {
return elm % 2 === 0;
});
result === 1; // true
Creates an Array
with the given arguments as its elements.
import { of } from '@dojo/framework/shim/array';
var array = of(0, 1, 2, 3);
array instanceof Array; // true
array[0] === 0; // true
array[1] === 1; // true
array[2] === 2; // true
array[3] === 3; // true