Computer >> Computer tutorials >  >> Programming >> Javascript

ArrayBuffer.slice() function in JavaScript


ArrayBuffer object in JavaScript represents a fixed-length binary data buffer.The slice() method of the this object returns a portion or, chunk from the array buffer (as a separate object). It accepts two integer arguments representing the start (inclusive) and end (exclusive) of the portion of the array to be returned.

Syntax

Its syntax is as follows

arrayBuffer.slice(start, end);

Example

Try the following example.

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var arrayBuffer = new ArrayBuffer(16);
      var int32View = new Int32Array(arrayBuffer);
      int32View[1] = 102;
      var sliced = new Int32Array(arrayBuffer.slice(4,12));
      document.write(" "+sliced);
   </script>
</body>
</html>

Output

102,0