<?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: Toukir Ahmed.Dev</title>
    <description>The latest articles on DEV Community by Toukir Ahmed.Dev (@ahmedturaj).</description>
    <link>https://dev.to/ahmedturaj</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%2F1252702%2Ffcf0ff42-bdca-4c58-a3dd-e13a827f294b.jpeg</url>
      <title>DEV Community: Toukir Ahmed.Dev</title>
      <link>https://dev.to/ahmedturaj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmedturaj"/>
    <language>en</language>
    <item>
      <title>Array Grouping In JavaScript (2024)</title>
      <dc:creator>Toukir Ahmed.Dev</dc:creator>
      <pubDate>Sat, 31 Aug 2024 14:17:35 +0000</pubDate>
      <link>https://dev.to/ahmedturaj/array-grouping-in-javascript-2024-3o1h</link>
      <guid>https://dev.to/ahmedturaj/array-grouping-in-javascript-2024-3o1h</guid>
      <description>&lt;p&gt;Array Grouping In JavaScript (2024)&lt;br&gt;
Array Grouping is not a new thing in JavaScript . Array Grouping is a new feature in JavaScript that helps developers organize elements in an array into groups based on a specific characteristic. This makes it easier to find and work with data.&lt;br&gt;
Now , the questions is how does it works ? &lt;br&gt;
well, before coming latest and modern method developer groups the array elements many different ways on of them is "reduce method".&lt;/p&gt;

&lt;p&gt;example : &lt;/p&gt;

&lt;p&gt;&lt;code&gt;const students = [&lt;br&gt;
{name: "SK Toukir", age: 21 },&lt;br&gt;
{name: "SK Turaj", age: 21},&lt;br&gt;
{name: "SK Jehan", age: 20},&lt;br&gt;
];&lt;br&gt;
const studentAges = student.reduce((result, student=&amp;gt;{&lt;br&gt;
const age = student.age;&lt;br&gt;
if( !result[ age ] ){&lt;br&gt;
result[ age ]= [ ];&lt;br&gt;
} result[ age ].push( student );&lt;br&gt;
return result;&lt;br&gt;
}),{});&lt;br&gt;
console.log( studentAges );&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But in modern JavaScript It become very easy , developers can do this in a minutes using "Object . groupBy" method or " array.group"&lt;br&gt;
method . &lt;br&gt;
1.Object . groupBy &lt;br&gt;
example :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const students = [&lt;br&gt;
{name: "SK Toukir", age: 21 },&lt;br&gt;
{name: "SK Turaj", age: 21},&lt;br&gt;
{name: "SK Jehan", age: 20},&lt;br&gt;
];&lt;br&gt;
const studentAges = Object.groupBy( students, ( student=&amp;gt;student.age ) );&lt;br&gt;
console.log( studentAges );&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In this method first developers write Object.groupBy (method name) it takes 2 paramiters. First paramiter will be the array name and the second paramiter will be a call back function and by that developers can easily groups the array elements.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;array.group 
example:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;const students = [&lt;br&gt;
{name: "SK Toukir", age: 21 },&lt;br&gt;
{name: "SK Turaj", age: 21},&lt;br&gt;
{name: "SK Jehan", age: 20},&lt;br&gt;
];&lt;br&gt;
const studentAges = students.group( student=&amp;gt;student.age );&lt;br&gt;
console.log( studentAges );&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The group() method takes the items in your array and sorts them into groups. Each group has a label (called a "key"), and the items that belong to that group are stored together in an array.&lt;/p&gt;

&lt;p&gt;Notice : If these tow method do not work in anyone's node version then open the terminal in your "vs code" the type "npm i core-js" then run the code again , hopefully it will work .&lt;/p&gt;

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