Skip to main content

Array Library Reference

The array library provides a comprehensive suite of functions for working with arrays (lists) in EasyBite. You can call these functions directly on array values using method syntax (e.g. [1,2,3].length()) or import the array module and invoke them as array.length(arr). You may also import specific functions with from array import append, remove.


Available Functions

FunctionParametersDescription
length(arr)arr (Array)Returns the number of elements in arr.
append(arr, value)arr (Array), value (any)Appends value to the end of arr and returns the modified array.
copy(arr)arr (Array)Returns a shallow copy of arr.
clear(arr)arr (Array)Removes all elements from arr and returns the now-empty array.
remove(arr, value)arr (Array), value (any)Removes the first occurrence of value from arr.
reverse(arr)arr (Array)Reverses the order of elements in arr.
insert(arr, index, value)arr (Array), index (Number), value (any)Inserts value at position index in arr.
sort(arr)arr (Array)Sorts arr in ascending order (numeric or lexicographic).
indexof(arr, value)arr (Array), value (any)Returns the zero-based index of the first occurrence of value, or -1 if not found.
pop(arr)arr (Array)Removes and returns the last element of arr, or null if empty.
shift(arr)arr (Array)Removes and returns the first element of arr, or null if empty.
unshift(arr, value)arr (Array), value (any)Inserts value at the start of arr and returns the modified array.
slice(arr, start, end)arr (Array), start, end (Numbers)Returns a new array containing elements from start up to (but not including) end.
splice(arr, start, count, ...items)arr (Array), start, count (Numbers), ...items (optional values)Removes count elements from start, returns the removed elements as an array, and inserts any items at start.
concat(arr1, arr2)arr1, arr2 (Arrays)Returns a new array which is the concatenation of arr1 and arr2.
includes(arr, value)arr (Array), value (any)Returns true if value is found in arr, otherwise false.

Examples

1. length(arr)

set arr to [10, 20, 30]
set len to arr.length()
show(len)
// Output:
// 3

import array
set len2 to array.length([1,2,3,4])
show(len2)
// Output:
// 4

2. append(arr, value)

set arr to [1, 2]
set newArr to arr.append(3)
show(newArr)
// Output:
// [1,2,3]

import array
set arr2 to [1,2]
set updated to array.append(arr2, 4)
show(updated)
// Output:
// [1,2,4]

3. copy(arr)

set orig to [5, 6, 7]
set copyArr to orig.copy()
show(copyArr)
// Output:
// [5,6,7]

import array
set result to array.copy([8,9])
show(result)
// Output:
// [8,9]

4. clear(arr)

set arr to [1,2,3]
set cleared to arr.clear()
show(cleared)
// Output:
// []

import array
set a to [4,5]
set cleared2 to array.clear(a)
show(cleared2)
// Output:
// []

5. remove(arr, value)

set arr to [1,2,3,2]
set updated to arr.remove(2)
show(updated)
// Output:
// [1,3,2]

import array
set removed from array.remove([1,2,3,2], 3)
show(removed)
// Output:
// [1,2,2]

6. reverse(arr)

set arr to [1,2,3]
set rev to arr.reverse()
show(rev)
// Output:
// [3,2,1]

import array
set rev2 to array.reverse([4,5,6])
show(rev2)
// Output:
// [6,5,4]

7. insert(arr, index, value)

set arr to [1,3]
set inserted to arr.insert(1, 2)
show(inserted)
// Output:
// [1,2,3]

import array
set arr3 to array.insert([1,3], 1, 9)
show(arr3)
// Output:
// [1,9,3]

8. sort(arr)

set arr to [3,1,2]
set sorted to arr.sort()
show(sorted)
// Output:
// [1,2,3]

import array
set sorted2 to array.sort([5,3,4])
show(sorted2)
// Output:
// [3,4,5]

9. indexof(arr, value)

set idx to [10,20,30].indexof(20)
show(idx)
// Output:
// 1

import array
set idx2 to array.indexof([1,2,3], 4)
show(idx2)
// Output:
// -1

10. pop(arr)

set arr to [1,2,3]
set lastVal to arr.pop()
show(lastVal)
show(arr)
// Output:
// 3
// [1,2]

11. shift(arr)

set arr to [1,2,3]
set firstVal to arr.shift()
show(firstVal)
show(arr)
// Output:
// 1
// [2,3]

12. unshift(arr, value)

set arr to [2,3]
set withNew to arr.unshift(1)
show(withNew)
// Output:
// [1,2,3]

import array
set withZero to array.unshift([2,3], 0)
show(withZero)
// Output:
// [0,2,3]

13. slice(arr, start, end)

set sliced to [1,2,3,4].slice(1,3)
show(sliced)
// Output:
// [2,3]

import array
set part to array.slice([5,6,7,8], 2, 4)
show(part)
// Output:
// [7,8]

14. splice(arr, start, count, ...items)

set arr to [1,2,3,4]
set removed to arr.splice(1,2,9,9)
show(removed)
show(arr)
// Output:
// [2,3]
// [1,9,9,4]

import array
set spliced to array.splice([5,6,7,8], 2, 1, 0)
show(spliced)
// Output:
// [7]

15. concat(arr1, arr2)

set combined to [1,2].concat([3,4])
show(combined)
// Output:
// [1,2,3,4]

import array
set joined to array.concat([5,6], [7,8])
show(joined)
// Output:
// [5,6,7,8]

16. includes(arr, value)

set exists to [1,2,3].includes(2)
show(exists)
// Output:
// true

import array
set found to array.includes([1,2,3], 4)
show(found)
// Output:
// false

Conclusion

The array library in EasyBite offers a full range of functions to create, inspect, modify, and combine arrays. You can:

  • Call these methods directly on array values using arr.method(...), or
  • Import the entire module with import array and use array.method(arr, ...), or
  • Import specific functions with from array import length, append and call them directly.

This flexibility ensures you write clean, readable, and efficient code for all your list‑manipulation needs.