AutoIt+
  • Overview
  • Getting started
  • The language
    • Basic
    • Grammar
      • Expressions
      • Statements
      • Declarations
    • Operators
    • Variables
    • Types & values
      • Null
      • Booleans
      • Numbers
      • Strings
      • Functions
      • Classes
      • Pointers
    • Control flow
      • If statement
      • For loop
      • While loop
      • Break & continue
      • Error handling
    • Collections
      • Array
        • APIs
        • Implementation
      • Map
        • APIs
        • Implementation
    • Modules
    • Exceptions
  • Built-in modules
    • C
      • APIs
      • Constants
    • Math
      • APIs
      • Constants
    • Task
      • Types
      • APIs
    • Global
  • The aup
    • Compiler
    • Runtime
    • Options
Powered by GitBook
On this page
  • Properties
  • .length
  • Methods
  • .push(value)
  • .pop()
  • .shift()

Was this helpful?

  1. The language
  2. Collections
  3. Array

APIs

This page provides API specifications of array.

Properties

.length

Return the number of elements in an array.

Example

Get length of an array

var nums = [1, 2, 3, 4]
puts nums.length    // 4

Get the last element in array

var arrOS = ['Windows', 'Linux', 'OSX']
puts arrOS[arrOS.length]    // OSX

Iterate through an array

var arr = [2, 4, 8, 10]
for i = 0, arr.length - 1 {
    puts arr[i]
}

.length is getter only, cannot assign value for this property.

Methods

.push(value)

Push value to an array

Parameters (1)

value : any

  • A value to be pushed

Return value

This method return the index of last pushed value in array.

var arr = [1, 2]
puts arr.push(5)    // 2
puts arr            // [1, 2, 5]

.pop()

Remove the last element of array

Parameters (0)

Return value

The last element of array.

var arr = [4, 5, 6]
puts arr.pop()    // 6
puts arr.length   // 2
puts arr          // [4, 5]

.shift()

Remove the first element of array.

Parameters (0)

Return value

The first element of array.

var arr = [7, 8, 9]
puts arr.shift()    // 7
puts arr        

PreviousArrayNextImplementation

Last updated 4 years ago

Was this helpful?