ArrayBuffer.isView() function in JavaScript

JavascriptWeb DevelopmentFront End Scripts

ArrayBuffer object in JavaScript represents a fixed-length binary data buffer. The isView() function of this object accepts an argument and verifies whether it is view of ArrayBuffer (DataView, typed array). If so, it returns true else, it returns false.

Syntax

Its syntax is as follows

arrayBuffer.isView(arg)

Example

Try the following example.

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var arrayBuffer = new ArrayBuffer(5);
      arrayBuffer = ["apple", "orange", "mango"];
      var bool = ArrayBuffer.isView(new Int32Array())
      document.write(bool);
   </script>
</body>
</html>

Output

true

Example

In the same way if we try executing this function by passing an object other than typed array or, a null value or, undefined value this function returns false.

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script>
      var arrayBuffer = new ArrayBuffer(5);
      arrayBuffer = ["apple", "orange", "mango"];
      var bool1 = ArrayBuffer.isView(new Int32Array());
      var bool2 = ArrayBuffer.isView();
      var bool3 = ArrayBuffer.isView(null);
      var bool4 = ArrayBuffer.isView(undefined);
      console.log(bool1);
      console.log(bool2);
      console.log(bool3);
      console.log(bool4);
   </script>
</body>
</html>

Output

True
false
false
false
raja
Published on 24-Oct-2018 10:57:22
Advertisements