<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: ddev2636</title>
    <description>The latest articles on Forem by ddev2636 (@ddev2636).</description>
    <link>https://forem.com/ddev2636</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F843115%2F3f010ac1-80b2-40d7-912c-e4f270ea130f.png</url>
      <title>Forem: ddev2636</title>
      <link>https://forem.com/ddev2636</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ddev2636"/>
    <language>en</language>
    <item>
      <title>Most Important Array functions in Javascript</title>
      <dc:creator>ddev2636</dc:creator>
      <pubDate>Wed, 13 Apr 2022 14:23:16 +0000</pubDate>
      <link>https://forem.com/ddev2636/most-important-array-functions-in-javascript-2888</link>
      <guid>https://forem.com/ddev2636/most-important-array-functions-in-javascript-2888</guid>
      <description>&lt;p&gt;As a beginner, I also face difficulty in remembering all the functions associated with a particular topic. So I thought of writing about some important and widely used array functions in javascript which I personally feel are very useful and a must know for beginners. However, one should have at least a basic idea of all the functions. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. Filter()
&lt;/h2&gt;

&lt;p&gt;The Filter() method creates a new array filled with              elements that pass a test provided by a function. However it does not change the original array.&lt;br&gt;
For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [32, 33, 16, 40];
const result = numbers.filter(checkNumber);

function checkNumber(number) {
  return number &amp;gt;= 30;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The filter will return [32,33,44] as these elements are greater than 30.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. forEach()
&lt;/h2&gt;

&lt;p&gt;The forEach() method calls a function for each elements in an array. It's somewhat similar to the &lt;strong&gt;for&lt;/strong&gt; loop for all elements.&lt;br&gt;
For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let text = "";
const numbers = [1,2,3,4]
numbers.forEach(functionMe);
document.getElementById("para").innerHTML = text;
function functionMe(item, index) {
  text += (index+1) + ": " + item + "&amp;lt;br&amp;gt;"; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output comes to be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1: 1
2: 2
3: 3
4: 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. map()
&lt;/h2&gt;

&lt;p&gt;The map() method creates a new array from the results of calling a function for every element.&lt;br&gt;
For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 4, 9, 16, 25];
document.getElementById("para").innerHTML = numbers.map(Math.sqrt);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will display the square root of every element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1,2,3,4,5 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Splice()
&lt;/h2&gt;

&lt;p&gt;Splice() method overwrites the original array by adding or removing elements.&lt;br&gt;
for example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const avengers = ["Captain America", "Iron Man", "Hulk", "Thor"];

fruits.splice(3, 0, "spider man", "Dr. Strange");
// here 3 signifies index, 0 signifies that no element is to be deleted .
//If we wish to delete some elements ,then index and number of elements to be deleted should be provided.

document.getElementById("para").innerHTML = fruits;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this will add 2 elements at the index 3. &lt;/p&gt;

&lt;p&gt;Hope this helps some peeps new to coding and web development.&lt;br&gt;
For more detailed explanation of these topics you may follow this playlist [(&lt;a href="https://www.youtube.com/playlist?list=PLgBH1CvjOA62PBFIDq55-S6Beivje30A2)"&gt;https://www.youtube.com/playlist?list=PLgBH1CvjOA62PBFIDq55-S6Beivje30A2)&lt;/a&gt;]&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
