Pardon the mess, Play My Code is in beta!

READY TO PLAY?
CLICK TO LOG IN!

sign up - lost password

Array Class

The array class is used for storing values in an ordered list. You can add, read and delete values from it. Each item is stored against an index value, which is a positive whole number.

// new Array examples
ns = [ 1, 2, 3 ]
ns = new Array()

// adding values
ns.add( 5 )
ns.push( 2 )
ns.unshift( 3 )

// iterating
ns.each() do |n|
    // code here
end

// iterating with key
ns.each() do |i, n|
    // code here
end

Note that if you set a value outside of the size of the array, then all of the empty values will be padded with 'null'.

new

add

index

indexes

includes

push

pop

shift

unshift

length

size

isEmpty

isSet

clear

delete

deleteAt

deleteIf

join

map

filter

fill

reverse

random

shuffle

sort

each

eachIndex

eachMapping

clone

flatten

See Also