请看以下代码所要解决的问题:
用Array.of()可以解决数组声明不一致的问题
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let hd=["abcde"];
hd[3]="housejh";
console.log(hd.length);//4
console.log(hd[2]);//undefined
console.log(hd);//Array(4) ["abcde",empty*2,"housejh"]
let cms=new Array(6);
console.log(cms.length);//6
console.log(cms);//Array(6)会导致有6个空值,实际我们想要一个值为6的数组
console.log(cms[2]);//undefined
//新版的ES中解决了这个问题,用Array.of()来进行解决这个问题
let arr1=Array.of(6);
console.log(arr1.length);//4
console.table(arr1);//Array(1)
console.log(arr1[0]);//6
console.log(arr1[1]);//undefined
// 直接使用字面量创建数组也会出现问题
//不是我们想要的结果,我们想要创建一个6个元素的数组
let arr2=[6,undefin