<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Semicolon's Blog]]></title><description><![CDATA[Semicolon's Blog]]></description><link>https://blog.semicolon.xyz</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1623175143740/xvfj1LO28.png</url><title>Semicolon&apos;s Blog</title><link>https://blog.semicolon.xyz</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 02:07:12 GMT</lastBuildDate><atom:link href="https://blog.semicolon.xyz/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Five Array methods to check or find item(s) in Array.]]></title><description><![CDATA[There are five different ways to check if an item or object exists within an array. 
Based on our use cases, we can use any of the array methods to achieve the same. 

Here in this blog, I will tell you the uses cases of all five array methods and al...]]></description><link>https://blog.semicolon.xyz/five-array-methods-to-check-or-find-items-in-array</link><guid isPermaLink="true">https://blog.semicolon.xyz/five-array-methods-to-check-or-find-items-in-array</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[array methods]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Khan M. Tabish]]></dc:creator><pubDate>Mon, 07 Jun 2021 17:51:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623088125632/cmZm3tINF.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>There are five different ways to check if an item or object exists within an array. 
Based on our use cases, we can use any of the array methods to achieve the same. </p>
<blockquote>
<p>Here in this blog, I will tell you the uses cases of all five array methods and also when and where it should be used.</p>
</blockquote>
<h2 id="arrayincludes">Array.includes</h2>
<p>Includes is checking that if the given item is present in the array or not.</p>
<blockquote>
<p>if item exist then it return <strong>true</strong> otherwise <strong>false</strong>.'</p>
</blockquote>
<p>We can't use the comparison operator in the <code>includes</code> like greater than or less than. It is only used to test the direct values.
Here is an example.</p>
<pre><code><span class="hljs-keyword">var</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">var</span> isNumberExist = numbers.includes(<span class="hljs-number">1</span>);
<span class="hljs-built_in">console</span>.log(isNumberExist); <span class="hljs-comment">//true</span>

<span class="hljs-keyword">var</span> isNumberExist = numbers.includes(<span class="hljs-number">7</span>);
<span class="hljs-built_in">console</span>.log(isNumberExist); <span class="hljs-comment">//false</span>
</code></pre><p>In the above example, I am checking that if the <code>1</code> is present in the <code>numbers</code> array or not. in that case, it's returning <strong>true</strong>. in the same way, when I am checking for the <code>7</code>, it's returning <strong>false</strong>.</p>
<h2 id="arraysome">Array.some</h2>
<p>This Array method returns a callback.</p>
<blockquote>
<p>This method is used to check if any of the array items is satisfying the condition, then it will return the <strong>true</strong> otherwise, it will return the <strong>false</strong>.</p>
</blockquote>
<p>Let me explain the same with an example.</p>
<pre><code><span class="hljs-keyword">var</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">var</span> isNumberExist = numbers.some(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> item &lt;= <span class="hljs-number">7</span>);
<span class="hljs-built_in">console</span>.log(isNumberExist); <span class="hljs-comment">//true</span>

<span class="hljs-keyword">var</span> isNumberExist = numbers.some(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> item &gt;= <span class="hljs-number">7</span>);
<span class="hljs-built_in">console</span>.log(isNumberExist); <span class="hljs-comment">//false</span>
</code></pre><p>In the above example, you can see that the first statement, <code>var isNumberExist = numbers.some((item) =&gt; item &lt;= 7);</code> is checking that if any of the items is less than or equal to 7 is present in the array. In that case, it's returning <strong>true</strong>.</p>
<p>and the second statement, <code>var isNumberExist = numbers.some((item) =&gt; item &gt;= 7);</code> is checking that if any of the array item is greater than or equal to 7 is present in the array or not. in that case its returning <strong>false</strong>.</p>
<h2 id="arrayevery">Array.every</h2>
<p>This Array method is also returning a callback.</p>
<blockquote>
<p><code>Array.every</code> method is just the opposite of the <code>Array.some</code>. It is checking that if all the items of the array is satisfying the given condition.</p>
</blockquote>
<p>Explaining this with the help of an example.</p>
<pre><code><span class="hljs-keyword">var</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">var</span> isNumberExist = numbers.every(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> item &lt;= <span class="hljs-number">7</span>);
<span class="hljs-built_in">console</span>.log(isNumberExist); <span class="hljs-comment">//true</span>

<span class="hljs-keyword">var</span> isNumberExist = numbers.every(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> item &gt;= <span class="hljs-number">3</span>);
<span class="hljs-built_in">console</span>.log(isNumberExist); <span class="hljs-comment">//false</span>
</code></pre><p>In this example, the first statement <code>numbers.every((item) =&gt; item &lt;= 7);</code> is checking that all the items of the array is less than 7. So in this case it is <strong>true</strong>. All the items of the array is less than or equal to 7.</p>
<p>The second statement <code>numbers.every((item) =&gt; item &gt;= 3);</code> is checking that if items of the array is greater than or equal to 3. so in that case only <code>3, 4 and 5</code> are greater than or equal to 3. SO it will return false.</p>
<h2 id="arrayfilter">Array.filter</h2>
<p>This Array method will also return a callback.</p>
<blockquote>
<p>Array.filter is used to filter the array on the basis of a condition. if condition satisfied then it will return an array with the matching items.</p>
</blockquote>
<p>Let's understand with the code.</p>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">numbers</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">isNumberExist</span> <span class="hljs-string">=</span> <span class="hljs-string">numbers.filter((item)</span> <span class="hljs-string">=&gt;</span> <span class="hljs-string">item</span> <span class="hljs-string">&lt;</span> <span class="hljs-number">7</span><span class="hljs-string">);</span>
<span class="hljs-string">console.log(isNumberExist);</span> <span class="hljs-string">//[1,</span> <span class="hljs-number">2</span><span class="hljs-string">,</span> <span class="hljs-number">3</span><span class="hljs-string">,</span> <span class="hljs-number">4</span><span class="hljs-string">,</span> <span class="hljs-number">5</span><span class="hljs-string">]</span>

<span class="hljs-string">var</span> <span class="hljs-string">isNumberExist</span> <span class="hljs-string">=</span> <span class="hljs-string">numbers.filter((item)</span> <span class="hljs-string">=&gt;</span> <span class="hljs-string">item</span> <span class="hljs-string">&gt;</span> <span class="hljs-number">3</span><span class="hljs-string">);</span>
<span class="hljs-string">console.log(isNumberExist);</span> <span class="hljs-string">//[4,</span> <span class="hljs-number">5</span><span class="hljs-string">]</span>
</code></pre><p>In the above example, the first filter statement <code>numbers.filter((item) =&gt; item &lt; 7);</code>is checking that if the array has numbers which are less than 7. so in that case, all the items of the array is less than 7. so it will return an array <code>[1, 2, 3, 4, 5]</code>.</p>
<p>The second statement <code>numbers.filter((item) =&gt; item &gt; 3);</code> is checking that, if items of the array is less than 3, if satisfied then it will return that matched items in the form of an array. so in this case it will return the <code>[4, 5]</code> because only <code>4 and 5</code> are greater than 3.</p>
<h2 id="arrayfind">Array.find</h2>
<p>The objective of this array method is to find an item within the array, but there is a catch in that.
It will not return all the matched item and it will also not return true or false. </p>
<blockquote>
<p>It will return the first matched item only.</p>
</blockquote>
<p>For example: </p>
<pre><code><span class="hljs-keyword">var</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">var</span> isNumberExist = numbers.find(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> item &lt; <span class="hljs-number">7</span>);
<span class="hljs-built_in">console</span>.log(isNumberExist); <span class="hljs-comment">//1</span>

<span class="hljs-keyword">var</span> isNumberExist = numbers.find(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> item &gt; <span class="hljs-number">3</span>);
<span class="hljs-built_in">console</span>.log(isNumberExist); <span class="hljs-comment">//4</span>
</code></pre><p>In the above case, the first statement <code>numbers.find((item) =&gt; item &lt; 7);</code> will return the 1 because the first matched item is 1.
the second statement <code>numbers.find((item) =&gt; item &gt; 3);</code> will return the 4, because the first matched item is 4 from the array which is greater than 3.</p>
<p>I hope now you will have some high-level idea about these array methods.
If I missed anything please add that in the comments. 
Thanks for reading the article. :) </p>
]]></content:encoded></item><item><title><![CDATA[Improve UI performance using window.onload event]]></title><description><![CDATA[window.onload
It called, when the entire page load including imges, css, DOM etc.
  window.onload = function(){
         console.log("Application Loaded")
  }
It is common for all of us front end developers that, sometime images are huge in size and ...]]></description><link>https://blog.semicolon.xyz/improve-ui-performance-using-windowonload-event</link><guid isPermaLink="true">https://blog.semicolon.xyz/improve-ui-performance-using-windowonload-event</guid><category><![CDATA[HTML5]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[CSS]]></category><category><![CDATA[UI]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Khan M. Tabish]]></dc:creator><pubDate>Sun, 23 May 2021 13:18:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1621775654001/8VqsJ0UQ2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="windowonload">window.onload</h2>
<p>It called, when the entire page load including <em>imges</em>, <em>css</em>, <em>DOM</em> etc.</p>
<pre><code>  <span class="hljs-built_in">window</span>.onload = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
         <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Application Loaded"</span>)
  }
</code></pre><p>It is common for all of us front end developers that, sometime images are huge in size and taking time to load on the application in that case our UI shows distorted. see the screen shot. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1621772838221/Of7x4_oWPT.png" alt="Window-Onload-KMT.png" />
In the above example, i used <em>window.onload</em>. that's why its showing loading message below the image because  the images are not fully loaded.</p>
<p>So this <em>winodw.onload</em> event can solve that issue. using this event we can show a loading message or block the screen or show placeholder images till the image or file not completely loaded.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1621773329225/uJDeT0wOq.png" alt="Window-Onload-KMT1.png" />
In the above image, you can see the message, "Application Loaded", it means all the resources are completely loaded now.</p>
<p>The complete code is here: </p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
            <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">onloaded</span>(<span class="hljs-params"></span>)</span>{
                <span class="hljs-keyword">var</span> status = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'status'</span>);
                <span class="hljs-keyword">var</span> loader = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'loader'</span>)
                status.innerText = <span class="hljs-string">"Application Loaded"</span>;
                loader.style.display=<span class="hljs-string">'none'</span>
            }
            <span class="hljs-built_in">window</span>.onload = onloaded;
        </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Window Onload | KMT<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"text-align: center;"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://images.pexels.com/photos/7974362/pexels-photo-7974362.jpeg"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"300px"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"400px"</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://images.pexels.com/photos/2377915/pexels-photo-2377915.jpeg"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"300px"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"400px"</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://images.pexels.com/photos/3626589/pexels-photo-3626589.jpeg"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"300px"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"400px"</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"display-6"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"status"</span>&gt;</span>Loading in progress...<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><p> <a target="_blank" href="https://github.com/kmtabish/window-events-methods">Download</a>  code from Git repo.</p>
<p> <a target="_blank" href="https://window-events.surge.sh/window.onload.html">Demo</a> </p>
]]></content:encoded></item><item><title><![CDATA[Access Device Camera from static HTML page using Javascript Camera API]]></title><description><![CDATA[Using Javascript Camera API you can access the device's Front and back camera from your Static HTML page. 
It doesn't required any library or module to be installed. you can do by just writing a small code. 
Will explain step by step.
First you have ...]]></description><link>https://blog.semicolon.xyz/access-device-camera-from-static-html-page-using-javascript-camera-api</link><guid isPermaLink="true">https://blog.semicolon.xyz/access-device-camera-from-static-html-page-using-javascript-camera-api</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[js]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[HTML]]></category><category><![CDATA[HTML Canvas]]></category><dc:creator><![CDATA[Khan M. Tabish]]></dc:creator><pubDate>Sat, 22 May 2021 13:09:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1621688841529/F_0UmeqbM.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Using Javascript Camera API you can access the device's Front and back camera from your Static HTML page. 
It doesn't required any library or module to be installed. you can do by just writing a small code. 
Will explain step by step.</p>
<p>First you have to add a html5 <strong>video</strong> tag to your <strong>index.html</strong></p>
<pre><code><span class="hljs-tag">&lt;<span class="hljs-name">video</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"video"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">video</span>&gt;</span>
</code></pre><p>In your <strong>camera.js</strong> file add the following code snippet.
First check if you browser is supporting <strong> navigator.mediaDevices</strong>.</p>
<pre><code><span class="hljs-selector-tag">if</span>(navigator &amp;&amp; navigator.mediaDevices){
    <span class="hljs-comment">//Your browser is supporting camera API.</span>
}<span class="hljs-selector-tag">else</span>{
    <span class="hljs-selector-tag">console</span><span class="hljs-selector-class">.log</span>(<span class="hljs-string">"camera API is not supported by your browser"</span>)
}
</code></pre><p>In the next step, we will add the camera API code.</p>
<pre><code><span class="hljs-keyword">if</span>(navigator &amp;&amp; navigator.mediaDevices){
    navigator.mediaDevices.getUserMedia(options)
    .then(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">stream</span>) </span>{
       <span class="hljs-comment">//use the stream to you code</span>
    })
    .<span class="hljs-keyword">catch</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
        <span class="hljs-comment">//Handle error here</span>
    });
}<span class="hljs-keyword">else</span>{
    console.log(<span class="hljs-string">"camera API is not supported by your browser"</span>)
}
</code></pre><p>as you can see that in the above code there is a parameter <strong>options</strong>. Its a configuration object which we will to pass to restrict or allow some of its feature.
For example, to allow the audio:</p>
<pre><code>{ <span class="hljs-attribute">audio</span>: true }
</code></pre><p>to access the front camera:</p>
<pre><code>{ <span class="hljs-attribute">video</span>: { facingMode: <span class="hljs-string">"user"</span> } }
</code></pre><p>to access the back camera:</p>
<pre><code>{ <span class="hljs-attribute">video</span>: { facingMode: { exact: <span class="hljs-string">"environment"</span> } } }
</code></pre><p>for more information about configuration, visit  <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia">this doc</a> .
We are almost done with the configuration, Now will assign stream to the video tag.</p>
<pre><code><span class="hljs-keyword">if</span>(navigator &amp;&amp; navigator.mediaDevices){
    <span class="hljs-keyword">const</span> options = { <span class="hljs-attr">audio</span>: <span class="hljs-literal">false</span>, <span class="hljs-attr">video</span>: { <span class="hljs-attr">facingMode</span>: <span class="hljs-string">"user"</span>, <span class="hljs-attr">width</span>: <span class="hljs-number">200</span>, <span class="hljs-attr">height</span>: <span class="hljs-number">200</span>  } }
    navigator.mediaDevices.getUserMedia(options)
    .then(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">stream</span>) </span>{
        <span class="hljs-keyword">var</span> video = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">'video'</span>);
        video.srcObject = stream;
        video.onloadedmetadata = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">e</span>) </span>{
          video.play();
        };
    })
    .catch(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
        <span class="hljs-comment">//Handle error here</span>
    });
}<span class="hljs-keyword">else</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"camera API is not supported by your browser"</span>)
}
</code></pre><p>So, We are almost done till now, now we will add a button to capture the image from the video and display it on canvas.
This is our final <strong>camera.js</strong> file</p>
<pre><code>
<span class="hljs-keyword">var</span> video, canvas, ctx;
<span class="hljs-keyword">if</span>(navigator &amp;&amp; navigator.mediaDevices){
    <span class="hljs-keyword">const</span> options = { <span class="hljs-attr">audio</span>: <span class="hljs-literal">false</span>, <span class="hljs-attr">video</span>: { <span class="hljs-attr">facingMode</span>: <span class="hljs-string">"user"</span>, <span class="hljs-attr">width</span>: <span class="hljs-number">300</span>, <span class="hljs-attr">height</span>: <span class="hljs-number">300</span>  } }
    navigator.mediaDevices.getUserMedia(options)
    .then(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">stream</span>) </span>{
        video = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">'video'</span>);
        video.srcObject = stream;
        video.onloadedmetadata = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">e</span>) </span>{
          video.play();
        };
        canvas = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"myCanvas"</span>);
        ctx = canvas.getContext(<span class="hljs-string">'2d'</span>);
    })
    .catch(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
        <span class="hljs-comment">//Handle error here</span>
    });
}<span class="hljs-keyword">else</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"camera API is not supported by your browser"</span>)
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">clickPhoto</span>(<span class="hljs-params"></span>) </span>{
   ctx.drawImage(video, <span class="hljs-number">0</span>,<span class="hljs-number">0</span>, canvas.width, canvas.height);
 }
</code></pre><p>Here is our final<strong> index.html</strong> file.</p>
<pre><code><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"text-align: center;"</span>&gt;</span>                                                   
          <span class="hljs-tag">&lt;<span class="hljs-name">video</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"video"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"text-align: center; border-radius: 20px;"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">video</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>  <span class="hljs-attr">style</span>=<span class="hljs-string">"text-align: center;"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn btn-warning"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"clickPhoto();"</span>&gt;</span>Take Photo<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
         <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"text-align: center;"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"myCanvas"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"300"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"300"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"text-align: center; border-radius: 20px;"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre><p> <a target="_blank" href="https://github.com/kmtabish/blog-js-camera-api">Download</a>  the final codebase repo.</p>
<p>See the  <a target="_blank" href="https://blog-js-camera-api.surge.sh/">demo</a>  here.</p>
<p>If you like the blog, please share it. 
Happy coding... :) </p>
]]></content:encoded></item><item><title><![CDATA[Javascript  Array Methods]]></title><description><![CDATA[Join
Joins array elements using provided separator and returns a string.
var numbers = [1, 2, 3, 4, 5];
var result = numbers.join(',');
console.log(result);
// Output: "1,2,3,4,5"
Reverse
Reverse the order of elements in the array. 
var numbers = [1,...]]></description><link>https://blog.semicolon.xyz/javascript-array-methods</link><guid isPermaLink="true">https://blog.semicolon.xyz/javascript-array-methods</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[array]]></category><category><![CDATA[array methods]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Khan M. Tabish]]></dc:creator><pubDate>Tue, 09 Mar 2021 12:25:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1615292443955/7u_oooQms.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="join">Join</h1>
<h3 id="joins-array-elements-using-provided-separator-and-returns-a-string"><em>Joins array elements using provided separator and returns a string.</em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">numbers</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">numbers.join(',');</span>
<span class="hljs-string">console.log(result);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span> <span class="hljs-string">"1,2,3,4,5"</span>
</code></pre><h1 id="reverse">Reverse</h1>
<h3 id="reverse-the-order-of-elements-in-the-array"><em>Reverse the order of elements in the array. </em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">numbers</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">numbers.reverse();</span>
<span class="hljs-string">console.log(result);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  [<span class="hljs-number">5</span>, <span class="hljs-number">4</span>, <span class="hljs-number">3</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>]
</code></pre><h1 id="sort">Sort</h1>
<h3 id="it-sorts-array-elements-using-default-sorting"><em>It Sorts array elements using default sorting. </em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">numbers</span> <span class="hljs-string">=</span> [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">1</span>, <span class="hljs-number">5</span>, <span class="hljs-number">4</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">numbers.sort();</span>
<span class="hljs-string">console.log(result);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
</code></pre><h1 id="concat">Concat</h1>
<h3 id="creates-and-return-a-new-array-that-contains-the-concatenation-of-arrays-on-which-it-is-invoked"><em>Creates and return a new array that contains the concatenation of arrays on which it is invoked. </em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">arr1</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">arr2</span> <span class="hljs-string">=</span> [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">arr1.concat(arr2)</span>
<span class="hljs-string">console.log(result,</span> <span class="hljs-string">arr1);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]<span class="hljs-string">,</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
</code></pre><h1 id="slice">Slice</h1>
<h3 id="returns-a-slicesubarray-of-the-array-but-it-will-not-affect-the-existing-array"><em> Returns a slice(subarray) of the array. but it will not affect the existing array </em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">arr1</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">arr1.slice(0,2)</span>
<span class="hljs-string">console.log(result,</span> <span class="hljs-string">arr1);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>]<span class="hljs-string">,</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
</code></pre><h1 id="splice">splice</h1>
<h3 id="general-purpose-method-for-insertion-and-removal-it-will-affect-the-existing-array"><em> General purpose method for insertion and removal. It will affect the existing array. </em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">arr1</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">arr1.splice(0,2)</span>
<span class="hljs-string">console.log(result,</span> <span class="hljs-string">arr1);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>]<span class="hljs-string">,</span> [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
</code></pre><h1 id="push">push</h1>
<h3 id="append-one-more-element-to-the-array"><em> Append One more element to the array </em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">arr1</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">arr1.push(6)</span>
<span class="hljs-string">console.log(arr1);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]
</code></pre><h1 id="pop">pop</h1>
<h3 id="deletes-the-last-element-of-the-array-and-returns-the-element"><em> Deletes the last element of the array and returns the element. </em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">arr1</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">arr1.pop()</span>
<span class="hljs-string">console.log(result,</span> <span class="hljs-string">arr1);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  <span class="hljs-number">5</span><span class="hljs-string">,</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
</code></pre><h1 id="shift">shift</h1>
<h3 id="removes-and-return-first-element-of-array"><em> Removes and return first element of array. </em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">arr1</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">arr1.shift()</span>
<span class="hljs-string">console.log(result,</span> <span class="hljs-string">arr1);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  <span class="hljs-number">1</span><span class="hljs-string">,</span> [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
</code></pre><h1 id="unshift">unshift</h1>
<h3 id="add-one-more-element-to-the-beginning-of-the-array-and-will-return-the-current-length-of-the-array"><em> Add one more element to the beginning of the array, and will return the current length of the array. </em></h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">arr1</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">arr1.unshift(7)</span>
<span class="hljs-string">console.log(result,</span> <span class="hljs-string">arr1);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  <span class="hljs-number">6</span><span class="hljs-string">,</span> [<span class="hljs-number">7</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
</code></pre><h1 id="indexof">indexOf</h1>
<h3 id="return-the-index-of-a-specified-elementstart-from-0-otherwise-return-1">* Return the index of a specified element(start from 0) otherwise return -1</h3>
<pre><code><span class="hljs-string">var</span> <span class="hljs-string">arr1</span> <span class="hljs-string">=</span> [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>]<span class="hljs-string">;</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">arr1.indexOf(4)</span>
<span class="hljs-string">console.log(result);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  <span class="hljs-number">3</span>
<span class="hljs-string">var</span> <span class="hljs-string">result</span> <span class="hljs-string">=</span> <span class="hljs-string">arr1.indexOf(7)</span>
<span class="hljs-string">console.log(result);</span>
<span class="hljs-string">//</span> <span class="hljs-attr">Output:</span>  <span class="hljs-number">-1</span>
</code></pre>]]></content:encoded></item></channel></rss>