ArrayBuffer.isView() function in JavaScript


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 25-Jun-2020

128 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements