<?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: Abimbola Oluwagbuyi</title>
    <description>The latest articles on DEV Community by Abimbola Oluwagbuyi (@bimbowande).</description>
    <link>https://dev.to/bimbowande</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%2F202776%2F4f8735b0-4c34-40d0-bbce-7193935340cb.jpg</url>
      <title>DEV Community: Abimbola Oluwagbuyi</title>
      <link>https://dev.to/bimbowande</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bimbowande"/>
    <language>en</language>
    <item>
      <title>13 Javascript one-liner tricks with Arrays.</title>
      <dc:creator>Abimbola Oluwagbuyi</dc:creator>
      <pubDate>Fri, 01 Jul 2022 18:25:19 +0000</pubDate>
      <link>https://dev.to/bimbowande/13-javascript-one-liner-tricks-with-arrays-5a38</link>
      <guid>https://dev.to/bimbowande/13-javascript-one-liner-tricks-with-arrays-5a38</guid>
      <description>&lt;p&gt;1.Calculate the sum of all the values 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;const arr= [1,4,5,7];
const arrSum = arr.reduce((a,b)=&amp;gt;a+b);
// valSum --  17
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.Generating array from a function arguments&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function generateArray() {
    return Array.from(arguments);
}
f(1,2,4))
//result -- [1,2,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.Sorting the value of an array in ascending order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sortArrayValues = (values) =&amp;gt; {
    if(!Array.isArray(values)){
      return null
    }
    return  values.sort((a,b)=&amp;gt;a-b);
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.Reverse the values 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;const fruits= ['Banana','Orange','Melon','Grape'];
const reverseFruits = fruits.reverse();
//result ['Grape','Melon','Orange','Banana'];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5.Removing the duplicates 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 fruits = ['banana','mango','apple','sugarcane','mango','apple']

let uniqueFruits = Array.from(new Set(fruits));

 // uniqueFruits -- [ 'banana', 'manago', 'apple', 'sugarcane' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6.Emptying 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 fruits = [3,'mango',6,9,'mango','apple']

fruits.length = 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7.Convert an array to an Object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arrayVal= ['Tokyo', 'Belfast','Birmigham', 'Lagos']

const fruitsObj = {...arrayVal};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;8.Merging multiple arrays into one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let fruits = ['banana','manago','apple'];
let meat = ["Poultry","beef","fish"]
let vegetables = ["Potato","tomato","cucumber"];
let food = [...fruits,...meat,...vegetables];

// food  -- ['banana',  'manago','apple',   'sugarcane','manago',  'apple','Poultry', 'beef','fish',    'Potato','tomato',  'cucumber'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;9.Replace a specific value 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;var fruits2 = ['apple', 'sugarcane', 'manago'];

fruits2.splice(0,2,"potato","tomato");

// fruits2  ['potato', 'tomato', 'apple', 'sugarcane', 'manago']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;10.Mapping array from objects without maps&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const friends = [
      {name:"John", age:22},
      {name:"Peter", age:23},
      {name:"bimbo",age:34},
      {name:"mark",age:45},
      {name:"Esther",age:21},
      {name:"Monica",age:19}
  ];

 let friendNames = Array.from(friends,({name})=&amp;gt;name);

 // friendNames --['John', 'Peter', 'bimbo', 'mark', 'Esther', 'Monica' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;11.Filling an array with data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let newArray = new Array(8).fill("3");

// result -- ['3', '3', '3', '3','3', '3', '3', '3']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;12.Merging only duplicates values in two arrays&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arrOne = [0,3,4,7,8,8];
let arrTwo = [1,2,3,4,8,6];

const duplicatedValue = [...new Set(arrOne)].filter(item=&amp;gt;arrTwo.includes(item));
// duplicatedValue -- [ 3, 4, 8]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;13.Remove falsy values 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;const mixedValues = [undefined,"blue",0,"",NaN,true,,"white",false];
const filteredArray = mixedArray.filter(Boolean);
//result [ 'blue', true, 'white' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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