Array Methods

All standard JavaScript array methods are supported.

.map()

Transform each element in an array.

bash
echo '[1, 2, 3]' | 1ls '.map(x => x * 2)'
# Output: [2, 4, 6]

.filter()

Keep elements that match a condition.

bash
echo '[1, 2, 3, 4, 5]' | 1ls '.filter(x => x > 2)'
# Output: [3, 4, 5]

.reduce()

Reduce an array to a single value.

bash
echo '[1, 2, 3, 4]' | 1ls '.reduce((sum, x) => sum + x, 0)'
# Output: 10

.find()

Find the first element matching a condition.

bash
echo '[{"id": 1}, {"id": 2}, {"id": 3}]' | 1ls '.find(x => x.id === 2)'
# Output: {"id": 2}

.findIndex()

Find the index of the first matching element.

bash
echo '[10, 20, 30]' | 1ls '.findIndex(x => x === 20)'
# Output: 1

.some()

Check if any element matches a condition.

bash
echo '[1, 2, 3]' | 1ls '.some(x => x > 2)'
# Output: true

.every()

Check if all elements match a condition.

bash
echo '[2, 4, 6]' | 1ls '.every(x => x % 2 === 0)'
# Output: true

.sort()

Sort array elements.

bash
echo '[3, 1, 2]' | 1ls '.sort((a, b) => a - b)'
# Output: [1, 2, 3]

.reverse()

Reverse the array order.

bash
echo '[1, 2, 3]' | 1ls '.reverse()'
# Output: [3, 2, 1]

.slice()

Extract a portion of an array.

bash
echo '[1, 2, 3, 4, 5]' | 1ls '.slice(1, 4)'
# Output: [2, 3, 4]

.flat()

Flatten nested arrays.

bash
echo '[[1, 2], [3, 4]]' | 1ls '.flat()'
# Output: [1, 2, 3, 4]

.flatMap()

Map then flatten the result.

bash
echo '[1, 2]' | 1ls '.flatMap(x => [x, x * 2])'
# Output: [1, 2, 2, 4]

.join()

Join array elements into a string.

bash
echo '["a", "b", "c"]' | 1ls '.join("-")'
# Output: "a-b-c"