Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

JavaScript의 TypedArray.entries() 함수

<시간/>

TypedArray의 entries() 함수는 해당 TypedArray 객체의 반복자를 반환하고 이를 사용하여 해당 객체의 키-값 쌍을 검색할 수 있습니다. 배열의 인덱스와 해당 인덱스의 요소를 반환하는 위치입니다.

구문

구문은 다음과 같습니다.

typedArray.entries()

예시

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55]);
      document.write("Contents of the typed array: "+int32View);
      document.write("<br>");
      var it = int32View.entries();
      for(i=0; i<int32View.length; i++) {
         document.write(it.next().value);
         document.write("<br>");
      }
   </script>
</body>
</html>

출력

Contents of the typed array: 21,64,89,65,33,66,87,55
0,21
1,64
2,89
3,65
4,33
5,66
6,87
7,55

예시

반복자가 배열의 끝을 가리킬 때 배열의 다음 요소에 액세스하려고 하면 결과로 정의되지 않습니다.

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55]);
      document.write("Contents of the typed array: "+int32View);
      document.write("<br>");
      var it = int32View.entries();
      for(i=0; i<int32View.length; i++) {
         document.write(it.next().value);
         document.write("<br>");
      }
      document.write(it.next().value);
   </script>
</body>
</html>

출력

Contents of the typed array: 21,64,89,65,33,66,87,55
0,21
1,64
2,89
3,65
4,33
5,66
6,87
7,55
undefined