From 0561e5a2c77214e6a1251d432ccf12c91d837281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BA=86=E6=B3=89?= Date: Tue, 18 Jul 2023 18:16:20 +0800 Subject: [PATCH] Update syntax-uts.md --- docs/tutorial/syntax-uts.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/tutorial/syntax-uts.md b/docs/tutorial/syntax-uts.md index f83067625..102b42baa 100644 --- a/docs/tutorial/syntax-uts.md +++ b/docs/tutorial/syntax-uts.md @@ -1678,6 +1678,12 @@ sort() 方法对数组的元素进行排序,并返回数组。 |:-:|:-:|:-:| |√|√|x| +```ts +const array2 = [5, 1, 4, 2, 3]; +array2.sort((a: number, b: number):number => a - b); +// expect(array2).toEqual([1, 2, 3, 4, 5]); +``` + #### splice splice() 方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容。此方法会改变原数组。 -- GitLab