<?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>DEV Community: Ahmed Ibrahim</title>
    <description>The latest articles on DEV Community by Ahmed Ibrahim (@ahmedibrahimgalal).</description>
    <link>https://dev.to/ahmedibrahimgalal</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%2F577192%2F9583a658-b997-4846-9e47-406c7fdebd2f.jpeg</url>
      <title>DEV Community: Ahmed Ibrahim</title>
      <link>https://dev.to/ahmedibrahimgalal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmedibrahimgalal"/>
    <language>en</language>
    <item>
      <title>Javascript array methods part 2</title>
      <dc:creator>Ahmed Ibrahim</dc:creator>
      <pubDate>Fri, 12 Feb 2021 13:02:04 +0000</pubDate>
      <link>https://dev.to/ahmedibrahimgalal/javascript-array-methods-part-2-57mn</link>
      <guid>https://dev.to/ahmedibrahimgalal/javascript-array-methods-part-2-57mn</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mcPbHvSa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1613048164018/hfdgCLBoB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mcPbHvSa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1613048164018/hfdgCLBoB.png" alt="1_AoOWn4UdPyuixXtkLQsQXA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Hello everyone in this article, we will know some of &lt;code&gt;Javascript Array Methods&lt;/code&gt;.
&lt;/h3&gt;

&lt;p&gt;Before, we learned about &lt;code&gt;push&lt;/code&gt;, &lt;code&gt;unshift&lt;/code&gt;, &lt;code&gt;splice&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://semantic-code.hashnode.dev/javascript-array-methods-part-1"&gt;Javascript array methods part 1&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;slice&lt;/code&gt; method
&lt;/h2&gt;

&lt;p&gt;slice method is used for get some elements form an array,&lt;br&gt;
but not remove any item from the old array.&lt;/p&gt;

&lt;p&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 arr = ["a", "b", "c", "d"];

alert( arr.slice(1, 3) ); // b,c (copy from 1 to 3)

alert( arr.slice(-2) ); // c,d (copy from -2 till the end)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;negative values that get values from the end.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;concat&lt;/code&gt; method
&lt;/h2&gt;

&lt;p&gt;The method &lt;code&gt;arr.concat&lt;/code&gt; creates a new array that includes values from other arrays and additional items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arr.concat(arg1, arg2...)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&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 arr = ['a', 'b'];

// create an array from: arr and ['c','d']
alert( arr.concat(['c', 'd']) ); // a,b,c,d

// create an array from: arr and ['c','d'] and ['e','f']
alert( arr.concat(['c','d'],  ['e','f']) ); // a,b,c,d,e,f

// create an array from: arr and ['c','d'], then add values 'e' and 'f'
alert( arr.concat(['c','d'], 'e', 'f') ); // a,b,c,d,e,f

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;Iterate forEach&lt;/code&gt; method
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;arr.forEach&lt;/code&gt; method that executes a function for every item in &lt;code&gt;arr&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;arr.forEach(function(item, index, array) {
  // ... do something with item
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Example, we can alert every item in an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [1,2,3];
arr.forEach(function(item){
alert(item); // 1 , 2 , 3
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can do anything with item. For example, you can make a filter for array elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [1,2,3],
secondArr = [];
arr.forEach(function(item){
if(item &amp;gt;= 2){
secondArr.push(item);
}
});
alert(secondArr); // 2,3

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Searching in array
&lt;/h2&gt;

&lt;p&gt;let's cover all method that search in an array.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;indexOf&lt;/code&gt;, &lt;code&gt;lastIndexOf&lt;/code&gt; and &lt;code&gt;includes&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The methods &lt;code&gt;arr.indexOf&lt;/code&gt;, &lt;code&gt;arr.lastIndexOf&lt;/code&gt; and &lt;code&gt;arr.includes&lt;/code&gt; have the same syntax.&lt;/p&gt;

&lt;p&gt;The Syntax: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;arr.indexOf(item, from);&lt;/code&gt;  find &lt;code&gt;item&lt;/code&gt; starting from the index &lt;code&gt;from&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arr.lastIndexOf(item, from)&lt;/code&gt; – same, but looks for from right to left.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arr.includes(item, from)&lt;/code&gt; – looks for &lt;code&gt;item&lt;/code&gt; starting from index &lt;code&gt;from&lt;/code&gt;, returns true if found.
&lt;/li&gt;
&lt;/ul&gt;

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

arr.indexOf(4, 1); // returns 3 is the index of number 4
arr.lastIndexOf(2) // returns 1 is the index of number 2
arr.includes(5) // returns true
arr.includes(10) // returns false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;find&lt;/code&gt; and &lt;code&gt;findIndex&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;If we have an array and we need to find any item with the specific condition.&lt;/p&gt;

&lt;p&gt;For Example:&lt;br&gt;
we have an array like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [
{
name: 'Ahmed',
age: 21
},
{
name: 'Mohamed',
age: 25
},
{
name: 'Mahmoud',
age: 23
}
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and, we need to get the object have an age equal 21.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let theObject = arr.find(function(item){
return item.age === 21;
});
console.log(theObject); // {name:'Ahmed', age:21}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;arr.findIndex&lt;/code&gt; method is essentially the same, but it returns the index where the element was found instead of the element itself and -1 is returned when nothing is found.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;filter&lt;/code&gt; method
&lt;/h2&gt;

&lt;p&gt;we use &lt;code&gt;arr.filter&lt;/code&gt; method to get an array from another array with specific condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [
{
name: 'Ahmed',
age: 21
},
{
name: 'Mohamed',
age: 25
},
{
name: 'Mahmoud',
age: 23
}
];

let newArr = arr.filter(function(item){
return item.age &amp;gt;= 23;
});
console.log(newArr ) // [{name:'Mahmoud', age:23}, {name:'Mohamed', age:25}];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;ul&gt;
&lt;li&gt;&lt;a href="https://semantic-code.hashnode.dev/javascript-array-methods-part-1" title="Javascript Array Methods Part 1"&gt; Javascript Array Methods Part 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://semantic-code.hashnode.dev/javascript-array-methods-part-2" title="Javascript Array Methods Part 2"&gt; Javascript Array Methods Part 2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;blockquote&gt;
&lt;p&gt;If you need to read the other parts of this article follow us:&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;Facebook Page : &lt;a href="https://www.facebook.com/semantic.code" title="Semantic Code"&gt;&lt;br&gt;
Semantic Code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hashnode :  &lt;a href="https://semantic-code.hashnode.dev/" title="Semantic Code"&gt;&lt;br&gt;
Semantic Code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dev.to :  &lt;a href="https://dev.to/ahmedibrahimgalal" title="Ahmed Ibrahim"&gt;&lt;br&gt;
Ahmed Ibrahim&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>webdev</category>
      <category>arraymethods</category>
    </item>
    <item>
      <title>Javascript Array Methods Part 1</title>
      <dc:creator>Ahmed Ibrahim</dc:creator>
      <pubDate>Wed, 10 Feb 2021 17:16:39 +0000</pubDate>
      <link>https://dev.to/ahmedibrahimgalal/javascript-array-methods-part-1-4gmk</link>
      <guid>https://dev.to/ahmedibrahimgalal/javascript-array-methods-part-1-4gmk</guid>
      <description>&lt;h1&gt;
  
  
  Javascript Array Methods
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Arrays in Javascript provide a lot of methods, To make things easier.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Add Items
&lt;/h2&gt;

&lt;p&gt;There are many ways to add items in an array Like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;push&lt;/li&gt;
&lt;li&gt;unshift&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
We use push method to add items to the end of an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [1,2,3,4];
arr.push(5);
console.log(arr); // [1,2,3,4,5]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, The second method is unshift is used for add items to the beginning.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [2,3,4];
arr.unshift(1);
console.log(arr); // [1,2,3,4]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to delete an element from the array?
&lt;/h2&gt;

&lt;p&gt;For delete any element form an array the is a &lt;code&gt;arr.splice()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;Let's know the syntax of &lt;code&gt;splice()&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [1,2,3];
arr.splice(startIndex, num_of_items, ...addItems);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if we have an array like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let names = ['Ahmed', 'Mohamed', 'Mahmoud', 'islam'];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, we need to delete any items. Easily we use &lt;code&gt;splice()&lt;/code&gt; method like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;names.splice(0,1); // here we say please start from index 0 and delete one item.
console.log(names); // ['Mohamed', 'Mahmoud' , 'islam']

let removed = names.splice(1, 1); 
console.log(removed); // ['Mahmoud']


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;we can add items after with delete items.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = ['hello', 'world'];
names.splice(0,1, ...arr);
console.log(names); // ['hello', 'world', 'Mohamed', 'Mahmoud', 'islam']

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;blockquote&gt;
&lt;p&gt;If you need to read the other parts of this article follow us:&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;Facebook Page : &lt;a href="https://www.facebook.com/semantic.code" title="Semantic Code"&gt;&lt;br&gt;
Semantic Code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hashnode :  &lt;a href="https://semantic-code.hashnode.dev/" title="Semantic Code"&gt;&lt;br&gt;
Semantic Code&lt;/a&gt;&lt;br&gt;
 dev.to :  &lt;a href="https://dev.to/ahmedibrahimgalal" title="Ahmed Ibrahim"&gt;&lt;br&gt;
Ahmed Ibrahim&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>webdev</category>
      <category>fullstack</category>
    </item>
  </channel>
</rss>
