githubEdit

Modifying An Array

Basic Operations

Arrays in OSL provide several methods for modification and access.

arr = [1, 2, 3, 4]

// Accessing elements (1-indexed)
first = arr[1]
// 1
second = arr[2]
// 2

// Modifying elements
arr[1] = 10
// [10, 2, 3, 4]

// Getting length
length = arr.len
// Number of elements

Adding and Removing Elements

Array Methods

Array Merging

Important Notes

  • Arrays are 1-indexed in OSL

  • Most operations create new copies

  • .trim() is used for array slicing

  • Destructuring can skip elements using empty slots

  • The ++ operator combines arrays

  • Methods like sort() and map() return new arrays

Last updated