APIs

Properties

.length

Getter

Return number of element in map

var trans = { en: 'Hello', vi: 'Xin chào' }
puts 'We have ' + trans.length + 'translations'

.keys

Getter

Return array of keys in map

var tup = { a: 4, b: 5 }
puts tup.keys    // [a, b]

Methods

.has(key)

Check if a key exists in map

Parameters (1)

key : A key for checking

Return value

This method returns true if the key has existed, otherwise is false.

var threeDee = true
var point = { x: 20, y: 50 }

if threeDee && !point.has('z') {
    point['z'] = 100
}

puts point    // { x: 20, y: 50, z: 100 }

.get(key)

.set(key, value)

Last updated

Was this helpful?