當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript TypedArray.fill()用法及代碼示例

TypedArray 對象的 fill() 函數用指定值(固定)替換數組的所有必需/期望元素。該函數接受三個數字,一個表示固定值,另外兩個表示要替換的元素部分的開始和結束索引(結束值是可選的)。

用法

其語法如下

int32View.fill(464, 3);

示例

<html>
<head>
   <title>JavaScript Array every Method</title>
</head>
<body>
   <script type="text/javascript">
      var int32View = new Int32Array([64, 89, 65,21, 14, 66, 87, 55]);
      document.write("Contents of the typed array:"+int32View);
      document.write("<br>");
      result = int32View.fill(464, 3);
      document.write("Contents of the typed array after fill:"+int32View);
   </script>
</body>
</html>

輸出

Contents of the typed array:64,89,65,21,14,66,87,55
Contents of the typed array after fill:64,89,65,464,464,464,464,464

相關用法


注:本文由純淨天空篩選整理自Samual Sam大神的英文原創作品 TypedArray.fill() function in JavaScript。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。