DataView.getInt8() function in JavaScript


The getInt8() function of the DataView gets and returns a signed 8-bit floating point number at the specified position.

Syntax

Its syntax is as follows

dataView.getInt8();

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var arrayBuffer = new ArrayBuffer(20);
      var dataView = new DataView(arrayBuffer);
      dataView.setInt8(1, 362);
      document.write(dataView.getInt8(1));
   </script>
</body>
</html>

Output

106

Example

To this function you cannot pass float value, if you try to do so it is considered as integer value.

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var arrayBuffer = new ArrayBuffer(20);
      var dataView = new DataView(arrayBuffer);
      dataView.setInt8(1, 362.23);
      document.write(dataView.getInt8(1));
   </script>
</body>
</html>

Output

106

Example

If nothing is stored in the dataview and if you still, try to get data, this function will return 0.

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var arrayBuffer = new ArrayBuffer(20);
      var dataView = new DataView(arrayBuffer);
      dataView.setInt8(1);
      document.write(dataView.getInt8(1));
   </script>
</body>
</html>

Output

0

Updated on: 25-Jun-2020

19 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements