Array to replace its item
Item to remove
Item to replace with
New replaced array
Deletes items and replaces new ones from passed starting index of an array
Example:
import { replace } from "@thalesrc/js-utils";
const array = ["a", "b", "c", "a", "b", "c"];
replace(array, {startingIndex: 3, deleteCount: 1, itemsToReplace: ['x', 'y']}); // ["a", "b", "c", "x", "y", "b", "c"];
Array Prototype Example:
import "@thalesrc/js-utils/dist/as-proto/array-replace";
const array = ["a", "b", "c", "a", "b", "c"];
array.replace({startingIndex: 3, deleteCount: 1, itemsToReplace: ['x', 'y']}); // ["a", "b", "c", "x", "y", "b", "c"];
Array to replace its item
Replace options
New replaced array
Deletes items and replaces new ones by passed matcher map
Example:
import { replace } from "@thalesrc/js-utils";
const array = ["a", "b", "c", "a", "b", "c"];
const map = new Map();
map.set("a", "x")
map.set("b", "y");
replace(array, {itemsToReplace: map}); // ["x", "y", "c", "a", "b", "c"];
replace(array, {itemsToReplace: map, multi: true}); // ["x", "y", "c", "x", "y", "c"];
Array Prototype Example:
import "@thalesrc/js-utils/dist/as-proto/array-replace";
const array = ["a", "b", "c", "a", "b", "c"];
const map = new Map();
map.set("a", "x")
map.set("b", "y");
array.replace({itemsToReplace: map}); // ["x", "y", "c", "a", "b", "c"];
array.replace({itemsToReplace: map, multi: true}); // ["x", "y", "c", "x", "y", "c"];
Array to replace its item
Replace options
New replaced array
Generated using TypeDoc
Replace
Replaces an item with passed one of an array
Example:
import { replace } from "@thalesrc/js-utils/array"; const array = ["a", "b", "c", "a", "b", "c"]; replace(array, "b", "x"); // ["a", "x", "c", "a", "b", "c"]
Array Prototype Example:
import "@thalesrc/js-utils/array/proto/replace"; const array = ["a", "b", "c", "a", "b", "c"]; array.replace("b", "x"); // ["a", "x", "c", "a", "b", "c"]
T Typeof array items