ToLength
A method to convert an argument to an integer suitable for use as the length of an array-like object. This method follows ECMAScript's specification for the 'ToLength' abstract operation.
Currently, this module only supports the ES2017 (ES8) specification.
npm
Installation Usingnpm install es-abstract-to-length
Example Usage
var toLength = console // => 0console // => 3console // => 42console // => 9001console // => 0console // => 0console // => 1 console // => 0console // => 0console // => 0 console // => 0console // => 9007199254740991
Documentation
API
ToLength ( argument )
The abstract operation ToLength converts argument to an integer suitable for use as the length of an array-like object.
A Number value is returned.
A TypeError
exception may be thrown for arguments that are Symbols or Objects
that lack a valueOf
method or a toString
method capable of returning a
non-object value.
argument
Type: *
The value to convert.
Related Projects
- es-abstract: a single library for multiple ECMAScript abstract operations.