Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-uni-app-x-zh
提交
526b5b67
U
unidocs-uni-app-x-zh
项目概览
DCloud
/
unidocs-uni-app-x-zh
通知
144
Star
2
Fork
33
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
9
列表
看板
标记
里程碑
合并请求
11
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-uni-app-x-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
9
Issue
9
列表
看板
标记
里程碑
合并请求
11
合并请求
11
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
526b5b67
编写于
9月 03, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[array]去除手动生成的代码
上级
341ef638
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
16 addition
and
101 deletion
+16
-101
docs/uts/buildin-object-api/array.md
docs/uts/buildin-object-api/array.md
+16
-101
未找到文件。
docs/uts/buildin-object-api/array.md
浏览文件 @
526b5b67
...
...
@@ -383,15 +383,7 @@ a.sort((a, b) : number => {
<!-- UTSJSON.Array.unshift.returnValue -->
```
ts
const
array1
=
[
1
,
2
,
3
];
console
.
log
(
array1
.
unshift
(
4
,
5
));
// expected output: 5
console
.
log
(
array1
);
// expected output: Array [4, 5, 1, 2, 3]
```
<!-- UTSJSON.Array.unshift.test -->
<!-- UTSJSON.Array.unshift.compatibility -->
...
...
@@ -403,20 +395,7 @@ console.log(array1);
<!-- UTSJSON.Array.indexOf.returnValue -->
```
ts
const
beasts
=
[
'
ant
'
,
'
bison
'
,
'
camel
'
,
'
duck
'
,
'
bison
'
];
console
.
log
(
beasts
.
indexOf
(
'
bison
'
));
// expected output: 1
// start from index 2
console
.
log
(
beasts
.
indexOf
(
'
bison
'
,
2
));
// expected output: 4
console
.
log
(
beasts
.
indexOf
(
'
giraffe
'
));
// expected output: -1
```
<!-- UTSJSON.Array.indexOf.test -->
<!-- UTSJSON.Array.indexOf.compatibility -->
...
...
@@ -428,15 +407,7 @@ console.log(beasts.indexOf('giraffe'));
<!-- UTSJSON.Array.lastIndexOf.returnValue -->
```
ts
const
animals
=
[
'
Dodo
'
,
'
Tiger
'
,
'
Penguin
'
,
'
Dodo
'
];
console
.
log
(
animals
.
lastIndexOf
(
'
Dodo
'
));
// expected output: 3
console
.
log
(
animals
.
lastIndexOf
(
'
Tiger
'
));
// expected output: 1
```
<!-- UTSJSON.Array.lastIndexOf.test -->
<!-- UTSJSON.Array.lastIndexOf.compatibility -->
...
...
@@ -448,12 +419,7 @@ console.log(animals.lastIndexOf('Tiger'));
<!-- UTSJSON.Array.every.returnValue -->
```
ts
const
isBelowThreshold
=
(
currentValue
:
number
):
boolean
=>
currentValue
<
40
;
const
array1
=
[
1
,
30
,
39
,
29
,
10
,
13
];
console
.
log
(
array1
.
every
(
isBelowThreshold
));
// expected output: true
```
<!-- UTSJSON.Array.every.test -->
<!-- UTSJSON.Array.every.compatibility -->
...
...
@@ -508,16 +474,7 @@ console.log(array1.every(isBelowThreshold));
<!-- UTSJSON.Array.some.returnValue -->
```
ts
const
array
=
[
1
,
2
,
3
,
4
,
5
];
// checks whether an element is even
const
even
=
(
element
:
number
):
boolean
=>
element
%
2
==
0
;
console
.
log
(
array
.
some
(
even
));
// expected output: true
```
<!-- UTSJSON.Array.some.test -->
<!-- UTSJSON.Array.some.compatibility -->
...
...
@@ -557,13 +514,7 @@ console.log(array.some(even));
<!-- UTSJSON.Array.forEach.returnValue -->
```
ts
const
array1
=
[
'
a
'
,
'
b
'
,
'
c
'
];
array1
.
forEach
(
element
=>
console
.
log
(
element
));
// expected output: "a"
// expected output: "b"
// expected output: "c"
```
<!-- UTSJSON.Array.forEach.test -->
> 特别注意:
> 不可在 forEach 的 callbackFn 里添加或者删除原数组元素,此行为是危险的,在 Android 平台会造成闪退,在 iOS 平台会造成行为不符合预期。如果想实现该效果,请用 while 循环。
...
...
@@ -626,16 +577,7 @@ while (index < array1.length) {
<!-- UTSJSON.Array.map.returnValue -->
```
ts
const
array1
=
[
1
,
4
,
9
,
16
];
// pass a function to map
const
map1
=
array1
.
map
((
x
:
number
):
number
=>
x
*
2
);
console
.
log
(
map1
);
// expected output: Array [2, 8, 18, 32]
```
<!-- UTSJSON.Array.map.test -->
<!-- UTSJSON.Array.map.compatibility -->
...
...
@@ -675,15 +617,7 @@ console.log(map1);
<!-- UTSJSON.Array.filter.returnValue -->
```
ts
const
words
=
[
'
spray
'
,
'
limit
'
,
'
elite
'
,
'
exuberant
'
,
'
destruction
'
,
'
present
'
];
const
result
=
words
.
filter
((
word
:
string
):
boolean
=>
word
.
length
>
6
);
console
.
log
(
result
);
// expected output: Array ["exuberant", "destruction", "present"]
```
<!-- UTSJSON.Array.filter_1.test -->
<!-- UTSJSON.Array.filter.compatibility -->
...
...
@@ -737,20 +671,7 @@ console.log(result);
<!-- UTSJSON.Array.reduce.returnValue -->
```
ts
const
array1
=
[
1
,
2
,
3
,
4
];
// 0 + 1 + 2 + 3 + 4
const
initialValue
=
0
;
const
sumWithInitial
=
array1
.
reduce
(
(
previousValue
:
number
,
currentValue
:
number
):
number
=>
previousValue
+
currentValue
,
initialValue
);
console
.
log
(
sumWithInitial
);
// expected output: 10
```
<!-- UTSJSON.Array.reduce.test -->
<!-- UTSJSON.Array.reduce.compatibility -->
...
...
@@ -833,6 +754,8 @@ console.log(sumWithInitial);
<!-- UTSJSON.Array.reduceRight.returnValue -->
<!-- UTSJSON.Array.reduceRight.test -->
<!-- UTSJSON.Array.reduceRight.compatibility -->
### reduceRight(callbackfn)
...
...
@@ -927,19 +850,7 @@ console.log(sumWithInitial);
<!-- UTSJSON.Array.isArray.returnValue -->
```
ts
console
.
log
(
Array
.
isArray
([
1
,
3
,
5
]));
// Expected output: true
console
.
log
(
Array
.
isArray
(
'
[]
'
));
// Expected output: false
console
.
log
(
Array
.
isArray
(
new
Array
(
5
)));
// Expected output: true
console
.
log
(
Array
.
isArray
(
new
Int16Array
([
15
,
33
])));
// Expected output: false
```
<!-- UTSJSON.Array.isArray.test -->
<!-- UTSJSON.Array.isArray.compatibility -->
...
...
@@ -951,6 +862,8 @@ console.log(Array.isArray(new Int16Array([15, 33])));
<!-- UTSJSON.Array.includes.returnValue -->
<!-- UTSJSON.Array.includes.test -->
<!-- UTSJSON.Array.includes.compatibility -->
### toKotlinList()
...
...
@@ -963,6 +876,8 @@ console.log(Array.isArray(new Int16Array([15, 33])));
<!-- UTSJSON.Array.toKotlinList.compatibility -->
<!-- UTSJSON.Array.toKotlinList.test -->
<!-- UTSJSON.Array.toKotlinList.tutorial -->
<!-- UTSJSON.Array.tutorial -->
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录