我想你正在寻找这个:
repeat for each key myKey in myArray
put myArray[myKey] & cr after msg
end repeat
你不需要那些花哨的 JS 东西。
如果你有一个数字数组,你可以这样做:
put item 2 of the extents of myArray into myMaxKey
put "something" into myArray[myMaxKey+1]
这将模拟 JS 中的推送命令。您也可以通过不同的方式执行此操作:
on mouseUp
put "a,b,c" into myArray
split myArray by comma
put the keys of myArray
combine myArray by tab
put tab & "d" after myArray
split myArray by tab
put cr & cr & the keys of myArray after msg
end mouseUp
如果要“模拟推送通知”,可以执行以下操作:
local lArray
on mouseUp
xpush 3
xpush 5
xpush 7
repeat for each key myKey in lArray
put lArray[myKey] & cr after field 1
end repeat
end mouseUp
on xpush theElem
local myMaxKey
put item 2 of the extents of lArray into myMaxKey
put theElem into lArray[myMaxKey+1]
end xpush
请注意,lArray 在所有处理程序之外声明,而 myMaxKey 在推送处理程序内部声明,即使两者都是局部变量。