包详细信息

calculate-from-index-x

Xotic7502.7kMIT3.1.2

Calculates a fromIndex of a given value for an array.

array, fromIndex, module, javascript

自述文件

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score Coverage Status

calculate-from-index-x

Calculates a fromIndex of a given value for an array.

module.exports(array, fromIndex)number

This method calculates a fromIndex of a given value for an array.

Kind: Exported function
Returns: number - The calculated fromIndex. Default is 0.
Throws:

  • TypeError If array is null or undefined.
Param Type Description
array array * The array on which to calculate the starting index.
fromIndex number * The position in this array at which to begin. A negative value gives the index of array.length + fromIndex by asc.

Example

import calcFromIndex from 'calculate-from-index-x';

console.log(calcFromIndex([1, 2, 3], 1)); // 1
console.log(calcFromIndex([1, 2, 3], Infinity)); // Infinity
console.log(calcFromIndex([1, 2, 3], -Infinity)); // 0
console.log(calcFromIndex([1, 2, 3], -1)); // 2