range
range creates an array starting from 0 with the length of the passed amount. This is a convenient way to generate a sequence of numbers you can map or loop over — for example when rendering a fixed number of placeholder/skeleton elements.
Usage examples
Basic
- 2.0 Build
- 1.0 Build
window.BAO.utils.range(5) // [0, 1, 2, 3, 4]
range(5) // [0, 1, 2, 3, 4]
Rendering placeholders
- 2.0 Build
- 1.0 Build
const skeletons = window.BAO.utils
.range(3)
.map((i) => `<div class="prd-Card prd-Card_Skeleton" data-index="${i}"></div>`)
.join('')
const skeletons = range(3)
.map((i) => `<div class="prd-Card prd-Card_Skeleton" data-index="${i}"></div>`)
.join('')