Skip to content
Mistium edited this page Feb 5, 2024 · 10 revisions

About Arrays in OSL

Arrays in OSL are defined by [] and can have any length and any data type in any item. This flexibility allows for arrays of arrays with JSON objects and integers in the same structure.

Example array:

["Hello", "Wow", 100, {"huh": 10}]

Commands

Defining an Array

To define an array, type the name of the array, followed by = and then the array data.

Example:

myArray = ["test", "data"]

Array Functions

  • .append("string"):

    • Adds a new element (in this case, a string) to the end of an array.
    • Example:
      myArray = ["hi"]
      myArray.append("goodbye")
      Results in ["hi", "goodbye"].
  • .index("string"):

    • Finds the index of a specific element (string) in an array.
    • Example:
      myArray = ["hi", "goodbye"]
      index = myArray.index("hi")
      index now contains 1, with array indices starting from 1.
  • .delete(int):

    • Removes an element at a specific index from an array.
    • Example:
      myArray = ["hi", "goodbye"]
      myArray.delete(1)
      Results in ["goodbye"].
  • .item(int) or .[int]:

    • Retrieves the item at a specific index in the array.
    • Example:
      myArray = ["hi", "goodbye"]
      item = myArray.item(1)
      item now contains "hi".
  • .join("string"):

    • Combines all elements of an array into a single string, separated by the specified separator.
    • Example:
      myArray = ["hello", "how are you"]
      result = myArray.join(", ")
      result now contains "hello, how are you".
  • .split("string"):

    • Splits a string into an array of substrings, separated by the specified separator.
    • Example:
      myString = "hello, how are you"
      resultArray = myString.split(" ")
      resultArray now contains ["hello,", "how", "are", "you"].
  • .insert(position, "string"):

    • Inserts a new element (string) at a specified position in the array.
    • Example:
      myArray = ["apple", "banana", "cherry"]
      myArray = myArray.insert(2, "orange")
      Results in ["apple", "orange", "banana", "cherry"]. The string "orange" is inserted at position 2, shifting the subsequent elements to make room.

originOS Wiki

Wiki Views:
:views

OSL | RSH | ICN

Clone this wiki locally