Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Hàm TypedArray.join() trong JavaScript

Hàm join() của TypedArray nối tất cả phần tử của mảng thành một chuỗi, cách nhau bởi dấu phân tách (mặc định là dấu phẩy). Trả về chuỗi kết quả.

Cú pháp

Cú pháp của nó như sau:

typedArray.join([separator])

Ví dụ

<html> <head>    <title>Ví dụ JavaScript TypedArray join</title> </head> <body>    <script type="text/javascript">       var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55]);       document.write("<br>");       var result1 = int32View.join('');       document.write("Không phân tách: "+result1);       document.write("<br>");       document.write("Dấu hai chấm: "+int32View.join(':'));       document.write("<br>");       document.write("Dấu gạch ngang: "+int32View.join('-'));       document.write("<br>");       document.write("Dấu cách: "+int32View.join(' '));    </script> </body> </html>

Kết quả

Không phân tách: 2119652114668755
Dấu hai chấm: 21:19:65:21:14:66:87:55
Dấu gạch ngang: 21-19-65-21-14-66-87-55
Dấu cách: 21 19 65 21 14 66 87 55