Skip to content

Latest commit

 

History

History
10 lines (8 loc) · 368 Bytes

fill-array.md

File metadata and controls

10 lines (8 loc) · 368 Bytes

Fill array

Use Array.map() to map values between start (inclusive) and end (exclusive) to value. Omit start to start at the first element and/or end to finish at the last.

const fillArray = (arr, value, start = 0, end = arr.length) =>
  arr.map((v, i) => i >= start && i < end ? value : v);
// fillArray([1,2,3,4],'8',1,3) -> [1,'8','8',4]