Socket
Socket
Sign inDemoInstall

negative-array

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    negative-array

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


Version published
Weekly downloads
1
decreased by-94.12%
Maintainers
1
Install size
4.25 kB
Created
Weekly downloads
 

Readme

Source

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.

Note: With Node.js 16.6.0, you can now use Array#at() instead of this package.

Install

$ npm install negative-array

Usage

import negativeArray from '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!
  • on-change - Watch an object or array for changes (Uses Proxy too)
  • known - Allow only access to known object properties (Uses Proxy too)

Keywords

FAQs

Last updated on 10 Aug 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc