<?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: Tiziano Cappai</title>
    <description>The latest articles on DEV Community by Tiziano Cappai (@tizianocappai_).</description>
    <link>https://dev.to/tizianocappai_</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%2F1067037%2F371c1a15-372e-40e8-bb11-8e7b47e8d002.jpeg</url>
      <title>DEV Community: Tiziano Cappai</title>
      <link>https://dev.to/tizianocappai_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tizianocappai_"/>
    <language>en</language>
    <item>
      <title>How to compare two arrays in Javascript</title>
      <dc:creator>Tiziano Cappai</dc:creator>
      <pubDate>Tue, 18 Apr 2023 07:42:59 +0000</pubDate>
      <link>https://dev.to/tizianocappai_/how-to-compare-two-arrays-in-javascript-1fe2</link>
      <guid>https://dev.to/tizianocappai_/how-to-compare-two-arrays-in-javascript-1fe2</guid>
      <description>&lt;p&gt;How many times have you found yourself having to verify if the contents of two arrays were equal? (It happens to me often)&lt;/p&gt;

&lt;p&gt;Now I’ll show you two ways to solve this problem:&lt;/p&gt;

&lt;p&gt;First approach: using JSON.stringify(), see more &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify"&gt;here&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// `a` and `b` are arrays
const isEqual = (a, b) =&amp;gt; JSON.stringify(a) === JSON.stringify(b);

// Examples
isEqual([1, 2, 3], [1, 2, 3]); // true
isEqual([1, 2, 3], [1, '2', 3]); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second approach using every(), see more &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every"&gt;here&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// `a` and `b` are arrays
const isEqual = (a, b) =&amp;gt; a.length === b.length &amp;amp;&amp;amp; a.every((v, i) =&amp;gt; v === b[i]);
// Examples
isEqual([1, 2, 3], [1, 2, 3]); // true
isEqual([1, 2, 3], [1, '2', 3]); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all, hope you re enjoining it! 🙂&lt;/p&gt;

&lt;p&gt;Want to connect? Reach out to me on &lt;a href="https://www.linkedin.com/in/tiziano-cappai-1b5271153/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
