<?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[Harpal Singh - Creator of Jai.js]]></title><description><![CDATA[Harpal Singh - Creator of Jai.js]]></description><link>https://hsk11.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 24 Nov 2026 13:13:22 GMT</lastBuildDate><atom:link href="https://hsk11.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Javascript Array Methods]]></title><description><![CDATA[Certainly! JavaScript arrays come with a rich set of built-in methods. Here's a brief description of some of the most commonly used ones: push(): Adds one…]]></description><link>https://hsk11.hashnode.dev/javascript-array-methods</link><guid isPermaLink="true">https://hsk11.hashnode.dev/javascript-array-methods</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[array]]></category><category><![CDATA[array methods]]></category><category><![CDATA[javascript framework]]></category><dc:creator><![CDATA[Harpal Singh]]></dc:creator><pubDate>Sat, 21 Oct 2023 11:07:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1697886407533/dfad9bbf-88b0-42fe-83ef-fcd51ce89e8b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Certainly! JavaScript arrays come with a rich set of built-in methods. Here's a brief description of some of the most commonly used ones:</p>
<ol>
<li><p><strong>push()</strong>: Adds one or more elements to the end of an array and returns the new length.</p>
</li>
<li><p><strong>pop()</strong>: Removes the last element from an array and returns it.</p>
</li>
<li><p><strong>shift()</strong>: Removes the first element from an array and returns it.</p>
</li>
<li><p><strong>unshift()</strong>: Adds one or more elements to the beginning of an array and returns the new length.</p>
</li>
<li><p><strong>splice()</strong>: Changes the contents of an array by removing, replacing, or adding elements.</p>
</li>
<li><p><strong>slice()</strong>: Returns a shallow copy of a portion of an array.</p>
</li>
<li><p><strong>concat()</strong>: Merges two or more arrays and returns a new array.</p>
</li>
<li><p><strong>forEach()</strong>: Executes a provided function once for each array element.</p>
</li>
<li><p><strong>map()</strong>: Creates a new array with the results of calling a provided function on every element.</p>
</li>
<li><p><strong>filter()</strong>: Creates a new array with all elements that pass the test provided by a function.</p>
</li>
<li><p><strong>reduce()</strong>: Applies a function against an accumulator and each element in the array to reduce it to a single value.</p>
</li>
<li><p><strong>reduceRight()</strong>: Same as reduce(), but processes the array elements from right to left.</p>
</li>
<li><p><strong>find()</strong>: Returns the first element that satisfies the provided testing function.</p>
</li>
<li><p><strong>findIndex()</strong>: Returns the index of the first element that satisfies the provided testing function.</p>
</li>
<li><p><strong>some()</strong>: Tests whether at least one element in the array passes the test implemented by the provided function.</p>
</li>
<li><p><strong>every()</strong>: Tests whether all elements in the array pass the test implemented by the provided function.</p>
</li>
<li><p><strong>sort()</strong>: Sorts the elements of an array in-place.</p>
</li>
<li><p><strong>reverse()</strong>: Reverses the elements of an array in-place.</p>
</li>
<li><p><strong>includes()</strong>: Determines whether an array includes a certain value.</p>
</li>
<li><p><strong>indexOf()</strong>: Returns the first index at which a given element can be found in the array.</p>
</li>
<li><p><strong>lastIndexOf()</strong>: Returns the last index at which a given element can be found in the array.</p>
</li>
<li><p><strong>isArray()</strong>: Determines whether the passed value is an array.</p>
</li>
<li><p><strong>join()</strong>: Joins all elements of an array into a string.</p>
</li>
<li><p><strong>toLocaleString()</strong>: Returns a string representing the elements of the array.</p>
</li>
<li><p><strong>flat()</strong>: Creates a new array with all sub-array elements concatenated.</p>
</li>
<li><p><strong>flatMap()</strong>: First maps each element using a mapping function, then flattens the result into a new array.</p>
</li>
</ol>
<ol>
<li><p><strong>push()</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>];
 fruits.push(<span class="hljs-string">'orange'</span>);  <span class="hljs-comment">// Returns 3, and fruits = ['apple', 'banana', 'orange']</span>
</code></pre>
</li>
<li><p><strong>pop()</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>];
 fruits.pop();  <span class="hljs-comment">// Returns 'banana', and fruits = ['apple']</span>
</code></pre>
</li>
<li><p><strong>shift()</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>];
 fruits.shift();  <span class="hljs-comment">// Returns 'apple', and fruits = ['banana']</span>
</code></pre>
</li>
<li><p><strong>unshift()</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>];
 fruits.unshift(<span class="hljs-string">'orange'</span>);  <span class="hljs-comment">// Returns 3, and fruits = ['orange', 'apple', 'banana']</span>
</code></pre>
</li>
<li><p><strong>splice()</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>, <span class="hljs-string">'cherry'</span>];
 fruits.splice(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-string">'orange'</span>);  <span class="hljs-comment">// fruits = ['apple', 'orange', 'cherry']</span>
</code></pre>
</li>
<li><p><strong>slice()</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>, <span class="hljs-string">'cherry'</span>];
 <span class="hljs-keyword">let</span> slicedFruits = fruits.slice(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>);  <span class="hljs-comment">// slicedFruits = ['banana', 'cherry']</span>
</code></pre>
</li>
<li><p><strong>concat()</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> arr1 = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
 <span class="hljs-keyword">let</span> arr2 = [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>];
 <span class="hljs-keyword">let</span> combined = arr1.concat(arr2);  <span class="hljs-comment">// combined = [1, 2, 3, 4, 5, 6]</span>
</code></pre>
</li>
<li><p><strong>forEach()</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> nums = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
 nums.forEach(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> <span class="hljs-built_in">console</span>.log(num * <span class="hljs-number">2</span>));  <span class="hljs-comment">// Outputs: 2, 4, 6</span>
</code></pre>
</li>
<li><p><strong>map()</strong>:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> nums = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
 <span class="hljs-keyword">let</span> doubled = nums.map(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> num * <span class="hljs-number">2</span>);  <span class="hljs-comment">// doubled = [2, 4, 6]</span>
</code></pre>
</li>
<li><p><strong>filter()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<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">let</span> evens = nums.filter(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> num % <span class="hljs-number">2</span> === <span class="hljs-number">0</span>);  <span class="hljs-comment">// evens = [2, 4]</span>
</code></pre>
</li>
<li><p><strong>reduce()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<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">let</span> sum = nums.reduce(<span class="hljs-function">(<span class="hljs-params">acc, curr</span>) =&gt;</span> acc + curr, <span class="hljs-number">0</span>);  <span class="hljs-comment">// sum = 15</span>
</code></pre>
</li>
<li><p><strong>reduceRight()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> chars = [<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>];
<span class="hljs-keyword">let</span> result = chars.reduceRight(<span class="hljs-function">(<span class="hljs-params">acc, curr</span>) =&gt;</span> acc + curr, <span class="hljs-string">''</span>);  <span class="hljs-comment">// result = 'cba'</span>
</code></pre>
</li>
<li><p><strong>find()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<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">let</span> firstEven = nums.find(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> num % <span class="hljs-number">2</span> === <span class="hljs-number">0</span>);  <span class="hljs-comment">// firstEven = 2</span>
</code></pre>
</li>
<li><p><strong>findIndex()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<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">let</span> index = nums.findIndex(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> num &gt; <span class="hljs-number">3</span>);  <span class="hljs-comment">// index = 3</span>
</code></pre>
</li>
<li><p><strong>some()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<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">let</span> hasEven = nums.some(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> num % <span class="hljs-number">2</span> === <span class="hljs-number">0</span>);  <span class="hljs-comment">// hasEven = true</span>
</code></pre>
</li>
<li><p><strong>every()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>];
<span class="hljs-keyword">let</span> allEven = nums.every(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> num % <span class="hljs-number">2</span> === <span class="hljs-number">0</span>);  <span class="hljs-comment">// allEven = true</span>
</code></pre>
</li>
<li><p><strong>sort()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<span class="hljs-number">3</span>, <span class="hljs-number">1</span>, <span class="hljs-number">4</span>, <span class="hljs-number">2</span>];
nums.sort();  <span class="hljs-comment">// nums = [1, 2, 3, 4]</span>
</code></pre>
</li>
<li><p><strong>reverse()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
nums.reverse();  <span class="hljs-comment">// nums = [3, 2, 1]</span>
</code></pre>
</li>
<li><p><strong>includes()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>, <span class="hljs-string">'cherry'</span>];
<span class="hljs-keyword">let</span> hasApple = fruits.includes(<span class="hljs-string">'apple'</span>);  <span class="hljs-comment">// hasApple = true</span>
</code></pre>
</li>
<li><p><strong>indexOf()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>, <span class="hljs-string">'cherry'</span>];
<span class="hljs-keyword">let</span> index = fruits.indexOf(<span class="hljs-string">'banana'</span>);  <span class="hljs-comment">// index = 1</span>
</code></pre>
</li>
<li><p><strong>lastIndexOf()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>];
<span class="hljs-keyword">let</span> lastIndex = nums.lastIndexOf(<span class="hljs-number">2</span>);  <span class="hljs-comment">// lastIndex = 3</span>
</code></pre>
</li>
<li><p><strong>isArray()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> isArr = <span class="hljs-built_in">Array</span>.isArray([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]);  <span class="hljs-comment">// isArr = true</span>
</code></pre>
</li>
<li><p><strong>join()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> elements = [<span class="hljs-string">'Fire'</span>, <span class="hljs-string">'Water'</span>, <span class="hljs-string">'Air'</span>];
<span class="hljs-keyword">let</span> joined = elements.join(<span class="hljs-string">'-'</span>);  <span class="hljs-comment">// joined = 'Fire-Water-Air'</span>
</code></pre>
</li>
<li><p><strong>toLocaleString()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> numbers = [<span class="hljs-number">1</span>, <span class="hljs-string">'a'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>()];
<span class="hljs-keyword">let</span> stringified = numbers.toLocaleString();  <span class="hljs-comment">// stringified will vary based on locale and might look like "1,a,10/20/2023"</span>
</code></pre>
</li>
<li><p><strong>flat()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nestedArr = [<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-keyword">let</span> flattened = nestedArr.flat(<span class="hljs-number">2</span>);  <span class="hljs-comment">// flattened = [1, 2, 3, 4]</span>
</code></pre>
</li>
<li><p><strong>flatMap()</strong>:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> nums = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
<span class="hljs-keyword">let</span> result = nums.flatMap(<span class="hljs-function"><span class="hljs-params">num</span> =&gt;</span> [num, num * <span class="hljs-number">2</span>]);  <span class="hljs-comment">// result = [1, 2, 2, 4, 3, 6]</span>
</code></pre>
</li>
</ol>
<p>Remember, these are just basic examples, and each method has its nuances that you can explore further in the official JavaScript documentation or by experimenting in your coding environment.</p>
]]></content:encoded></item></channel></rss>