<?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: Ezzdin Atef</title>
    <description>The latest articles on DEV Community by Ezzdin Atef (@ezzdinatef).</description>
    <link>https://dev.to/ezzdinatef</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%2F202509%2F0eb8f462-5dac-4cc8-a14a-a3071cab081e.jpeg</url>
      <title>DEV Community: Ezzdin Atef</title>
      <link>https://dev.to/ezzdinatef</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ezzdinatef"/>
    <language>en</language>
    <item>
      <title>eCommerce Database Design</title>
      <dc:creator>Ezzdin Atef</dc:creator>
      <pubDate>Fri, 17 Nov 2023 19:04:14 +0000</pubDate>
      <link>https://dev.to/ezzdinatef/ecommerce-database-design-1ggc</link>
      <guid>https://dev.to/ezzdinatef/ecommerce-database-design-1ggc</guid>
      <description>&lt;p&gt;Building eCommerce is one of the most famous web application that we build as it got so famous, well known, and the need of it is became more than ever for ordering and shipping products to your home online.&lt;/p&gt;

&lt;p&gt;One of the most challenges that I have faces while building many eCommerce application is the complicity that it gain with more features that's required from the client and we have to add. That's made me think about the pros and cons of my structure specially the database design and started ask my self many questions like, Is my design is suitable for these requirement?, Did I get the most clean structure I can get?, Is this affect with performance and loading data efficiency?.&lt;/p&gt;

&lt;p&gt;Until this moment I write this blog, this the database design that I get into conclusion to be best fit to the needs that I have faced before (until I got new project with more complicated requirement 🤡).&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Project Description &amp;amp; Requirements
&lt;/h2&gt;

&lt;p&gt;First of all, as any application we have users that can register and login to our eCommerce application. Every user have one or more addresses. They have also favorite or Wishlist, Orders list to list there orders and its status, and Cart list of all the products that's ready to be ordered.&lt;/p&gt;

&lt;p&gt;We have categories and sub categories (2 levels of categories) and each have a name and description.&lt;/p&gt;

&lt;p&gt;For sure we have products and this have many things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic information of the product like: name, description, price, summary, cover image, ...etc.&lt;/li&gt;
&lt;li&gt;Product gallery which consist of many images of the product.&lt;/li&gt;
&lt;li&gt;Every product may have some attributes like sizes, and colors.&lt;/li&gt;
&lt;li&gt;Some products that have many colors will have image gallery for every color separated.&lt;/li&gt;
&lt;li&gt;Every color, size, or both might there prices vary. let's say that the blue t-shirt will cost &lt;code&gt;20$&lt;/code&gt; but the red t-shirt will cost &lt;code&gt;22$&lt;/code&gt; . even the xl blue t-shirt will cost &lt;code&gt;22$&lt;/code&gt; but the XXL blue t-shirt will cost &lt;code&gt;26$&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Every color and size have limited quantity stock like we might have from the XXL blue t-shirt 3 items but XXXL blue t-shirt just 1 item.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When user make an order will choose one of his addresses with the order and he might pay online with any supported way like visa or something else (will integrate with payment gateway).&lt;/p&gt;

&lt;p&gt;When the order is out for delivery then the quantity of all products will decrease.&lt;/p&gt;

&lt;p&gt;Now, that's all with the requirements of the project so let's get our mind around it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Designing
&lt;/h2&gt;

&lt;p&gt;As we notice from the previous section that the most complex part is the product, here where the game play go xD.&lt;/p&gt;

&lt;p&gt;Let's start from the beginning of our database design.&lt;/p&gt;

&lt;h3&gt;
  
  
  Users Table
&lt;/h3&gt;

&lt;p&gt;Let's start with the users table and its related information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc4kzf6rhsmrhispgfcn2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc4kzf6rhsmrhispgfcn2.png" alt="Users Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we just have 2 tables, one for users information details, and the other one for the addresses that's associated to the user and linked in &lt;code&gt;one to many&lt;/code&gt; relationship using the &lt;code&gt;user_id&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Categories Table
&lt;/h3&gt;

&lt;p&gt;Now in the categories table, We have 2 tables one for main categories, and the other for sub categories. sub categories table associated to the categories in &lt;code&gt;one to many&lt;/code&gt; relationship.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv99b1076n35s0wd4qoll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv99b1076n35s0wd4qoll.png" alt="Categories Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Products Table
&lt;/h3&gt;

&lt;p&gt;Now, The products table, Let’s start with simple structure that have the basic information of the product and linked within the categories (will be linked in &lt;code&gt;many to many&lt;/code&gt; relationship with sub categories table). See image bellow.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgyxklhnxsmj8335y20i3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgyxklhnxsmj8335y20i3.png" alt="Products Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s try to take a more higher look, as mention above the products will have many different attribute (in our situation here are colors, and sizes) and they might be with different prices range, So let’s remove the price column from the products table because that will be linked in other table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuy0jh6y6u39xmsfs8jk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuy0jh6y6u39xmsfs8jk.png" alt="Products Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we notice above, we added new table called &lt;code&gt;product_attributes&lt;/code&gt; that will hold all product attributes types and there values from different colors and sizes.&lt;/p&gt;

&lt;p&gt;Then will create &lt;code&gt;product_skus&lt;/code&gt; table that will link between products and the attribute together as we added 2 columns both point to the &lt;code&gt;product_attributes&lt;/code&gt; table but, one for colors and the other for sizes (we can add more if we need to).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: We may split the &lt;code&gt;product_attributes&lt;/code&gt; table to 2 more table like &lt;code&gt;product_colors&lt;/code&gt;, and &lt;code&gt;product_sizes&lt;/code&gt; but I think of &lt;code&gt;product_attributes&lt;/code&gt; table idea more easily extendable as we can add more attributes sizes in same table but will add just one more column in &lt;code&gt;products_skus&lt;/code&gt; table.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Each &lt;code&gt;product_skus&lt;/code&gt; entity have a price and quantity value that may vary between every attributes variation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wishlist Table
&lt;/h3&gt;

&lt;p&gt;The Wishlist table is quite simple as we will just store the &lt;code&gt;product_id&lt;/code&gt; and the &lt;code&gt;user_id&lt;/code&gt;. That’s it 😀.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbf3i9b7dgk9199oixzoh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbf3i9b7dgk9199oixzoh.png" alt="Wishlist Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Cart Table
&lt;/h3&gt;

&lt;p&gt;This table is what’s holding the products that customer wants to buy and order so we will have a table called &lt;code&gt;cart&lt;/code&gt; which connected to the &lt;code&gt;user&lt;/code&gt; table and have total cost attribute.&lt;/p&gt;

&lt;p&gt;The other table is &lt;code&gt;cart_item&lt;/code&gt; which is linked to the cart table and carry the &lt;code&gt;product&lt;/code&gt; and &lt;code&gt;product sku&lt;/code&gt; tables and the quantity required by the customer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F18yu4nb8bhlw03mhu8uk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F18yu4nb8bhlw03mhu8uk.png" alt="Cart Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown above, the 2 tables are very simple.&lt;/p&gt;

&lt;h3&gt;
  
  
  Orders Table
&lt;/h3&gt;

&lt;p&gt;The order table is same as cart tables we have &lt;code&gt;order&lt;/code&gt; and &lt;code&gt;order_item&lt;/code&gt; (but will call the &lt;code&gt;order&lt;/code&gt; as &lt;code&gt;order_details&lt;/code&gt;). Just will have one more table that will be responsible for the payments will be named &lt;code&gt;payment_details&lt;/code&gt; which will hold all the payment information from order, amount, provider, and status. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd6f9ai0mopmez0qpb2qi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd6f9ai0mopmez0qpb2qi.png" alt="Orders Table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown above, this is the order and payment tables to store all needed info that we need for now or event we can add more attributes as required.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Schema
&lt;/h3&gt;

&lt;p&gt;Now let’s look into the big picture of our schema.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flkhag5kifjx0zv2f9ktk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flkhag5kifjx0zv2f9ktk.png" alt="Final Schema"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s the preview link to play with it on &lt;a href="https://dbdiagram.io/d/eCommerce-Database-Design-65521cb47d8bbd6465131f01" rel="noopener noreferrer"&gt;dbdiagram.io&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Here we reach to the end of this article, I hope you enjoyed. If you have any suggestion or comments, please write it down and I'll be happy to share thoughts with you. &lt;/p&gt;

&lt;p&gt;See you again 😀;&lt;/p&gt;

</description>
      <category>database</category>
      <category>backend</category>
      <category>performance</category>
    </item>
    <item>
      <title>What's Pure Function in JavaScript</title>
      <dc:creator>Ezzdin Atef</dc:creator>
      <pubDate>Sun, 02 Apr 2023 12:23:48 +0000</pubDate>
      <link>https://dev.to/ezzdinatef/whats-pure-function-in-javascript-44ck</link>
      <guid>https://dev.to/ezzdinatef/whats-pure-function-in-javascript-44ck</guid>
      <description>&lt;p&gt;Hello World,&lt;/p&gt;

&lt;p&gt;One of the most known questions, especially in interviews, is about pure functions and what they are… so we will talk about pure functions in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  what are pure functions?
&lt;/h2&gt;

&lt;p&gt;It’s the atomic building block of functional programming. they are very simple and easy to test.&lt;/p&gt;

&lt;p&gt;The function can be called a pure function if these conditions are applied:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The same inputs always return the same outputs&lt;/li&gt;
&lt;li&gt;No side effects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s focus on each of them:&lt;/p&gt;

&lt;h3&gt;
  
  
  The same inputs always return the same outputs
&lt;/h3&gt;

&lt;p&gt;This means that we always get the same output whenever we use the function and pass the same input.&lt;/p&gt;

&lt;p&gt;for example, we have this function.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// will return always 5&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;whenever we pass the same input &lt;code&gt;2, 3&lt;/code&gt;, we get the same output &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But in the following example.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// will return 7&lt;/span&gt;
&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// will return 9&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;we have a shared state here, which is a bad practice (we don’t use it unless we need to do things that way) because we can’t predict the return value of the function now, and became not a pure function.&lt;/p&gt;

&lt;p&gt;So in summary, a pure function is a function that returns the same output always whenever we call it and pass the same input.&lt;/p&gt;

&lt;h3&gt;
  
  
  No side effects
&lt;/h3&gt;

&lt;p&gt;the side effects of a function are one of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mutating your input&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;console.log&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;HTTP calls (AJAX/fetch)&lt;/li&gt;
&lt;li&gt;Changing the filesystem&lt;/li&gt;
&lt;li&gt;Querying the DOM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In general, the function implementation should be only about calculating the final output and nothing else.&lt;/p&gt;

&lt;p&gt;Note: we should not always use pure function and it’s not the best solution as may you think, because we might need to call HTTP requests, change the file system, or query the DOM tree.&lt;/p&gt;

&lt;p&gt;That’s it for today’s article, if you have any suggestions, then don’t hesitate to contact me anytime.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Slice vs Splice in JavaScript</title>
      <dc:creator>Ezzdin Atef</dc:creator>
      <pubDate>Wed, 23 Jun 2021 12:34:34 +0000</pubDate>
      <link>https://dev.to/ezzdinatef/slice-vs-splice-in-javascript-42ef</link>
      <guid>https://dev.to/ezzdinatef/slice-vs-splice-in-javascript-42ef</guid>
      <description>&lt;p&gt;Hello everyone 👋&lt;/p&gt;

&lt;p&gt;when I started learning JavaScript, I was confused about slice &amp;amp; splice methods so, thus I will try to explain it simply without going deep in it so you understand it easily without any confusion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Slice
&lt;/h2&gt;

&lt;p&gt;Slice means to cut something into pieces or slices. In JavaScript, we use to cut a part of the array as we need just a partial part of the array.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;slice method tasks 2 parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;start: the start index of the array where I should strat cut it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;end: the end index where I should stop cutting&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: That the end index will not be a part of the sliced array&lt;/p&gt;

&lt;h3&gt;
  
  
  Examples
&lt;/h3&gt;

&lt;p&gt;In The First Example, I want to get from index 1 to the element before index 4&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 6&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 7&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// will return ["Item 2", "Item 3", "Item 4"]&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;In The Second Example, we want to get from index 3 to the end of the array&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 6&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 7&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// will return ["Item 4", "Item 5", "Item 6", "Item 7", "Item 8"]&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;so here we didn't specify the end parameter and when we do that he will take the rest of the array until the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  Splice
&lt;/h2&gt;

&lt;p&gt;Splice means to connect or join. we use it if we want to add something to the array but in a specific place unlike push or unshift which adds new elements to the end or the beginning of the array. and we use It also to remove something from the array from a specific place.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;deleteCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;itemN&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;start: the start index of the array where I should start changing it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;deleteCount: the number of elements that I want to delete and if I don't want to remove anything we simply pass 0&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then the rest of the parameters is the elements we want to add to the array ^_^&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Examples
&lt;/h3&gt;

&lt;p&gt;In The First Example, I just want to remove 3 elements from the array starting from the element of index 2&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 6&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 7&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// will return ["Item 1", "Item 2", "Item 6", "Item 7", "Item 8"]&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;In The Second Example, we want to add some new elements from index 5 without removing any elements from the array so will be the first element I will add will be in index 5&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 6&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 7&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;item 9&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;item 10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// will return  ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "item 9", "item 10", "Item 6", "Item 7", "Item 8"]&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;In The Third Example, Now let us remove some elements and replace it with other new elements 😄&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 6&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 7&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;&lt;br&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;item 9&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;item 10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// will return  ["Item 1", "Item 2", "item 9", "item 10", "Item 6", "Item 7", "Item 8"]&lt;/span&gt;&lt;/p&gt;

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

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Conclusion&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;So that's it 😀. Slice returns part of an array while splice adds &amp;amp; removes some elements of an array from a specific index.&lt;br&gt;
Of course, there is a more complex example &amp;amp; usage for them which you can check out later to have a deep understanding of it.&lt;/p&gt;

&lt;p&gt;I hope you find this article helpful 🤗&lt;/p&gt;

&lt;p&gt;see you next time ✌&lt;/p&gt;

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