プロジェクト
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
関連プロジェクトを探す
読み込み中…