<?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: Isabella</title>
    <description>The latest articles on DEV Community by Isabella (@isabella417).</description>
    <link>https://dev.to/isabella417</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F564090%2Fead8424e-21ce-4e08-a304-fc8b69e6ee85.jpg</url>
      <title>DEV Community: Isabella</title>
      <link>https://dev.to/isabella417</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/isabella417"/>
    <language>en</language>
    <item>
      <title>Useful array methods with JavaScript</title>
      <dc:creator>Isabella</dc:creator>
      <pubDate>Mon, 08 Feb 2021 18:23:06 +0000</pubDate>
      <link>https://dev.to/isabella417/useful-array-methods-with-javascript-3cnm</link>
      <guid>https://dev.to/isabella417/useful-array-methods-with-javascript-3cnm</guid>
      <description>&lt;p&gt;First, We need to know what's an array and what is used for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Array&lt;/strong&gt; is a data structure that consists of a collection of elements (number, boolean, string, object, ...) and we commonly use it to organize and represent a group of elements that are related to each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; An array of objects that represent users of a system with their year of birth and the role they perform.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const users = [
    { name: "Daniel", birthYear: 1996, role: "Sysadmin" },
    { name: "Sarah", birthYear: 1993, role: "Sysadmin" },
    { name: "Stiven", birthYear: 2000, role: "Tester" },
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On some occasions we will see it necessary to perform operations with the arrays to filter or obtain information regarding it.&lt;/p&gt;

&lt;p&gt;To do this we can use some methods that will allow us to manipulate and extract information regarding the array that we use in a simple way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some of these methods are:
&lt;/h2&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  Filter
&lt;/h3&gt;

&lt;p&gt;Filter helps us to obtain the elements within the array that fulfill a truth condition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; We want to get all the users that their role is "Sysadmin".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;truth condition&lt;/strong&gt;: When users.role is equal to "Sysadmin".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sysadminUsers = users.filter(user =&amp;gt; user.role === "Sysadmin") 
/* returns [{name: "Daniel", birthYear: 1996, role: "Sysadmin"},{name: "Sarah", birthYear: 1993, role: "Sysadmin"}] */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  Map
&lt;/h3&gt;

&lt;p&gt;Map helps us perform a task on each of the elements of the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; We want to get the age of each of the users.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const currentYear = new Date().getFullYear();
const AgedUsers = users.map(user =&amp;gt; currentYear - user.birthYear);
/* returns [25,28,21] */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  Some
&lt;/h3&gt;

&lt;p&gt;Some check if one or more elements fulfill a truth condition, if it happens return true else false.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; We want to know if exist a user with role "Tester" and "Developer".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; users.some(user =&amp;gt; user.role ==="Tester") // returns true
 users.some(user =&amp;gt; user.role ==="Developer") // returns false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  Every
&lt;/h3&gt;

&lt;p&gt;Every check if all elements fulfill a truth condition&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,2,3,4,5,6,7,8,9]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; We want to know if all numbers in the above array are greater than 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;numbers.every(number =&amp;gt; number &amp;gt; 0) //returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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