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
-
JavaScriptのTypedArray.values()関数
TypedArrayのvalues()関数は、型付き配列の値を保持するイテレータオブジェクトを返します。 next()メソッドは、イテレータオブジェクトの次の要素を返します。 構文 その構文は次のとおりです typedArray.values() 例 <html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript">
-
JavaScriptで関数の引数として配列を渡す方法は?
関数の引数として配列を渡す 昔は、関数の引数として配列を渡す必要がある場合は、 apply() およびnull 使用すべきです。 nullの使用 コードを汚れたにします 。したがって、コードをクリーンにし、配列を関数の引数として渡すために、スプレッド オペレーターが写真に登場します。 スプレッドを使用する apply()を使用する必要のない演算子 関数。一言で言えばそれについて話し合いましょう。 例 次の例では、 nullを使用しています。 およびapply() 配列を関数の引数として渡します。これは廃止された方法です。この方法は、拡散する最新の方法に置き換えられています。 演算