js-helpers

ModIndex

ModIndex (Array array, index)

Treats array as a linked list. An array with 3 items at index 3 would return array[0]. Normally array[3] would be undefined.

Arguments

Array array

Any array

Number index

Any non-negative, non-infinity number.

Use

import { ModIndex } from "@taystack/js-helpers";

const arr = [1,2,3];
ModIndex(arr, 0)   // 1
ModIndex(arr, 3)   // 1
ModIndex(arr, 300) // 1

Source: @taystack/js-helpers hosted on GitHub Author: taystack