Need help with negative-array?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

sindresorhus
425 Stars 29 Forks MIT License 35 Commits 0 Opened issues

Description

Negative array index support `array[-1]` using ES2015 Proxy

Services available

!
?

Need anything else?

Contributors list

# 80
Shell
exec
test-fr...
nextjs
28 commits
# 1,795
PureScr...
mdl
materia...
Flask
1 commit
# 16,432
JavaScr...
regl
Shell
plotly-...
1 commit
# 155,654
Shell
CSS
ecmascr...
Node.js
1 commit
# 7,406
TypeScr...
iterm2
Node.js
exec
1 commit
# 6,862
chalk
iterm2
exec
Electro...
1 commit

negative-array

Negative array index support

array[-1]
using ES2015
Proxy

JavaScript doesn't natively support the use of a negative index to get items backwards from the end, but with ES2015 Proxy it's possible. Take a look at the source to see how simple it is to implement and read this short article about it.

Install

$ npm install negative-array

Usage

const negativeArray = require('negative-array');

// Adds negative array index support to any given array const unicorn = negativeArray(['🐴', '🎂', '🌈']);

// Get the last item by using a negative index console.log(unicorn[-1]); //=> '🌈'

// OMG, YES!

Related

  • on-change - Watch an object or array for changes (Uses
    Proxy
    too)
  • known - Allow only access to known object properties (Uses
    Proxy
    too)

License

MIT © Sindre Sorhus

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.