arry

Better than Array.

Usage no npm install needed!

<script type="module">
  import arry from 'https://cdn.skypack.dev/arry';
</script>

README

Arry

Arry is an improved version of Javscript's Array, with support for python-like in syntax and the ability to access items from end of the array (arr[-1]). It also supports search queries (arr['< 4']) to quickly access items. It is otherwise intended to work as you'd expect the native Array to work.

const arr = new Arry(1, 2, 3, 4, 5);

Check if a value is in the array

if (1 in arr) {
  ...
}

Get the last item in the array

const last = arr[-1];
const thirdLast = arr[-3];

Search with queries

// all items bigger than 3
arr['> 3']; // [4, 5]

// && and || operators
arr['> 1 && < 5']; // [2, 3, 4]

// search item properties
arr.push({ prop: 1 }, { prop: 2 });
arr['prop == 1']; // { prop: 1 }

Looping

for (const item of arr) {
  ...
}

Other useful functions

arr.pull('foo'); // remove all items matching 'foo'
arr.remove(0); // remove at index
arr.length === ~arr; // quick access to length
arr.crush(); // remove all null or undefined values