26 lines
474 B
Markdown
26 lines
474 B
Markdown
|
---
|
|||
|
title: 数组
|
|||
|
updated: 2022-03-15 07:59:11Z
|
|||
|
created: 2022-03-15 07:44:09Z
|
|||
|
---
|
|||
|
|
|||
|
|
|||
|
## 提取数组的key
|
|||
|
这个并不比直接用`for in` 快,map内部就是用的`for in`。
|
|||
|
```js
|
|||
|
var str = {}
|
|||
|
table.map(num,lambda(v,k,r) table.push(str,v) )
|
|||
|
```
|
|||
|
|
|||
|
## 更改数组的元素
|
|||
|
```js
|
|||
|
var num1 = table.map(num,lambda(v,k) tonumber(v) )
|
|||
|
```
|
|||
|
## 交换数组的key和value
|
|||
|
可同时处理数组元素
|
|||
|
```js
|
|||
|
var newt=table.map(t,function(v,k,result){
|
|||
|
result[tonumber(v)]=k
|
|||
|
})
|
|||
|
```
|