The setInt16() function of the DataView stores a signed 16-bit integer at the specified position.
Syntax
Its syntax is as follows
dataView.setInt16();
Example
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var arrayBuffer = new ArrayBuffer(20); var dataView = new DataView(arrayBuffer); dataView.setInt16(1, 3225); document.write(dataView.getInt16(1)); </script> </body> </html>
Output
3225
Example
To this function you cannot pass float value, if you try to do so it is considered as integer value.
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var arrayBuffer = new ArrayBuffer(20); var dataView = new DataView(arrayBuffer); dataView.setInt16(1, 564.22); document.write(dataView.getInt16(1)); </script> </body> </html>
Output
564
Example
If nothing is stored in the dataview and if you still, try to get data, this function will return 0.
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var arrayBuffer = new ArrayBuffer(20); var dataView = new DataView(arrayBuffer); dataView.setInt16(1); document.write(dataView.getInt16(1)); </script> </body> </html>
Output
0