https://github.com/igorskyflyer/uarray
🎉 Provides UArray, an Array type that supports negative indices/indexes, just wrap your regular JavaScript array with UArray() and you are all set! 🙌
https://github.com/igorskyflyer/uarray
array back-end custom extension igorskyflyer index indexer javascript negative uarray
Last synced: 6 months ago
JSON representation
🎉 Provides UArray, an Array type that supports negative indices/indexes, just wrap your regular JavaScript array with UArray() and you are all set! 🙌
- Host: GitHub
- URL: https://github.com/igorskyflyer/uarray
- Owner: igorskyflyer
- License: mit
- Created: 2021-07-04T18:17:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T23:17:53.000Z (over 2 years ago)
- Last Synced: 2025-04-12T15:06:48.935Z (6 months ago)
- Topics: array, back-end, custom, extension, igorskyflyer, index, indexer, javascript, negative, uarray
- Language: JavaScript
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## UArray
![]()
Provides `UArray`, an `Array` type that supports negative indices/indexes, just wrap your _regular_ JavaScript array with `UArray()` or pass the elements directly to `UArray()` and you are all set! 🎉🙌
⚠ Uses the built-inProxy
object, check browser compatibility on the Can I Use website.
📢 This is the pure vanilla JavaScript version of this project, if you are looking for the npm-version, check here.
### Usage
ℹ Works like negative indices in other languages, e.g. **-1** picks that **last** element, **-2,** the **second to last**, etc.
✨ Since `v.1.1.0` the function signature has been changed and now it supports 2 different ways of action. You can now pass a single parameter of type `Array` or multiple parameters of any primitive type.
### Example
```js
const food = UArray(['🍟', '🌭', '🍿', '🥙', '🥓']) // array passed
const objects = UArray('🎈', '🎩', '⚽', '🥇', '🎯') // no array passed, just direct valuesconsole.log(food[-1]) // prints '🥓'
console.log(food[-3]) // prints '🍿'
console.log(objects[-1]) // prints '🎯'
console.log(objects[-3]) // prints '⚽'
```
🎉 Happy coding! 🙌