列表/Hash 方法
push(expr, args…)
将args添加到expr中。
nums = 1 2
push(nums, 3, 4, 5)
nums
// => 1 2 3 4 5
相当于append()
pop(expr)
返回最后一个值
nums = 4 5 3 2 1
num = pop(nums)
nums
// => 4 5 3 2
num
// => 1
shift(expr)
返回第一个值
nums = 4 5 3 2 1
num = shift(nums)
nums
// => 5 3 2 1
num
// => 4
unshift(expr, args…)
向expr添加args并排序
nums = 4 5
unshift(nums, 3, 2, 1)
nums
// => 1 2 3 4 5
相当于prepend()
.
index(list, value)
返回列表中值的(从0开始)索引。
list = 1 2 3
index(list, 2)
// => 1
index(1px solid red, red)
// => 2
keys(pairs)
返回给定pairs中的keys。
pairs = (one 1) (two 2) (three 3)
keys(pairs)
// => one two three
values(pairs)
返回给定pairs中的values。
pairs = (one 1) (two 2) (three 3)
values(pairs)
// => 1 2 3
list-separator(list)
返回list的分隔符。
list1 = a b c
list-separator(list1)
// => ' '
list2 = a, b, c
list-separator(list2)
// => ','
length([expr])
带括号的表达式可以作为数组,length()函数返回此类表达式的长度。
length((1 2 3 4))
// => 4
length((1 2))
// => 2
length((1))
// => 1
length(())
// => 0
length(1 2 3)
// => 3
length(1)
// => 1
length()
// => 0
last(expr)
返回expr中的最后一个值:
nums = 1 2 3
last(nums)
last(1 2 3)
// => 3
list = (one 1) (two 2) (three 3)
last(list)
// => (three 3)
网友评论