DataView.setUint32() function in JavaScript

JavascriptWeb DevelopmentFront End Scripts

<p>The <strong>setUint32()</strong> function of the <strong>DataView</strong> stores an unsigned 32-bit integer at the specified position.</p><h2>Syntax</h2><p>Its syntax is as follows</p><pre class="result notranslate">dataView.setUint32();</pre><h2>Example</h2><p><a class="demo" href="http://tpcg.io/Bl1N9b" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate" style="">&lt;html&gt; &lt;head&gt; &nbsp; &nbsp;&lt;title&gt;JavaScript Example&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &nbsp; &nbsp;&lt;script type=&quot;text/javascript&quot;&gt; &nbsp; &nbsp; &nbsp; var arrayBuffer = new ArrayBuffer(20); &nbsp; &nbsp; &nbsp; var dataView = new DataView(arrayBuffer); &nbsp; &nbsp; &nbsp; dataView.setUint32(1, 45544); &nbsp; &nbsp; &nbsp; document.write(dataView.getUint32(1)); &nbsp; &nbsp;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</pre><h2>Output</h2><pre class="result notranslate">45544</pre><h2>Example</h2><p>To this function you cannot pass float value, if you try to do so it is considered as integer value.</p><p><a class="demo" href="http://tpcg.io/sByn4Y" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate" style="">&lt;html&gt; &lt;head&gt; &nbsp; &nbsp;&lt;title&gt;JavaScript Example&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &nbsp; &nbsp;&lt;script type=&quot;text/javascript&quot;&gt; &nbsp; &nbsp; &nbsp; var arrayBuffer = new ArrayBuffer(20); &nbsp; &nbsp; &nbsp; var dataView = new DataView(arrayBuffer); &nbsp; &nbsp; &nbsp; dataView.setUint32(1, 455.44); &nbsp; &nbsp; &nbsp; document.write(dataView.getUint32(1)); &nbsp; &nbsp;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</pre><h2>Output</h2><pre class="result notranslate">455.44</pre><h2>Example</h2><p>If nothing is stored in the dataview and if you still, try to get data, this function will return 0.</p><p><a class="demo" href="http://tpcg.io/zypz9p" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate" style="">&lt;html&gt; &lt;head&gt; &nbsp; &nbsp;&lt;title&gt;JavaScript Example&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &nbsp; &nbsp;&lt;script type=&quot;text/javascript&quot;&gt; &nbsp; &nbsp; &nbsp; var arrayBuffer = new ArrayBuffer(20); &nbsp; &nbsp; &nbsp; var dataView = new DataView(arrayBuffer); &nbsp; &nbsp; &nbsp; dataView.setUint32(1); &nbsp; &nbsp; &nbsp; document.write(dataView.getUint32(1)); &nbsp; &nbsp;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt;</pre><h2>Output</h2><pre class="result notranslate">0</pre>
raja
Updated on 25-Jun-2020 10:22:03

Advertisements