要创建零填充的JavaScript数组,请使用Unit8Array类型的数组。
您可以尝试运行以下代码:
<html> <body> <script> var arr1 = ["marketing", "technical", "finance", "sales"]; var arr2 = new Uint8Array(4); document.write(arr1); document.write("<br>Zero filled array: "+arr2); </script> </body> </html
输出结果
marketing,technical,finance,sales Zero filled array: 0,0,0,0