项目
在 GitHub 查看
sindresorhus/negative-array
关于
使用 ES2015 Proxy 支持负数组索引(`array[-1]`)。
系统与基础设施实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文negative-array
Negative array index support
array[-1]using ES2015Proxy
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!
Related
探索相关项目
加载中…