Skip to content

πŸŽ‰ Provides UArray, an Array type that supports negative indices/indexes, just wrap your regular JavaScript array with UArray() and you are all set! πŸ™Œ

License

Notifications You must be signed in to change notification settings

igorskyflyer/UArray

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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-in Proxy 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


const food = UArray(['🍟', '🌭', '🍿', 'πŸ₯™', 'πŸ₯“']) // array passed
const objects = UArray('🎈', '🎩', '⚽', 'πŸ₯‡', '🎯') // no array passed, just direct values

console.log(food[-1]) // prints 'πŸ₯“'
console.log(food[-3]) // prints '🍿'
console.log(objects[-1]) // prints '🎯'
console.log(objects[-3]) // prints '⚽'

πŸŽ‰ Happy coding! πŸ™Œ

About

πŸŽ‰ Provides UArray, an Array type that supports negative indices/indexes, just wrap your regular JavaScript array with UArray() and you are all set! πŸ™Œ

Topics

Resources

License

Stars

Watchers

Forks