# 代码片段
# 判断两个数组是否相同
const arr1 = [1, 2, 3];
const arr2 = [1, 2, 3];
const result = arr1.every((record, i) => record === arr2[i]);
console.log("对比结果=" + result);
1
2
3
4
5
2
3
4
5
# 使用定时器模拟异步操作
const delay = (t: number) => new Promise((resolve) => setTimeout(resolve, t));
async function printConsole() {
await delay(1000);
return Promise.reject(false);
}
(async () => {
try {
let res = await printConsole();
console.log(res);
} catch (error) {
console.log(error);
}
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15