<?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: Serkan Sayhan</title>
    <description>The latest articles on DEV Community by Serkan Sayhan (@codepumps).</description>
    <link>https://dev.to/codepumps</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%2F373681%2F345dbd45-ac54-4427-9f00-513ace6ab344.jpeg</url>
      <title>DEV Community: Serkan Sayhan</title>
      <link>https://dev.to/codepumps</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codepumps"/>
    <language>en</language>
    <item>
      <title>What is the difference splice, slice, and split method in Javascript ?</title>
      <dc:creator>Serkan Sayhan</dc:creator>
      <pubDate>Fri, 30 Oct 2020 13:13:12 +0000</pubDate>
      <link>https://dev.to/codepumps/what-is-the-difference-splice-slice-and-split-method-in-javascript-3mll</link>
      <guid>https://dev.to/codepumps/what-is-the-difference-splice-slice-and-split-method-in-javascript-3mll</guid>
      <description>&lt;p&gt;Today, I want to talk about &lt;strong&gt;split()&lt;/strong&gt;, &lt;strong&gt;splice()&lt;/strong&gt;, and &lt;strong&gt;slice()&lt;/strong&gt; method. You know there are lots of functions with scarily similar names in land of javascript. That's why javascript methods can be confused each other sometimes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Split()
&lt;/h2&gt;

&lt;p&gt;Split is a function that split the given string into an array of substrings. The split method doesn't change the original string array and will return the new array.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&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%2Fi%2Fr525ecv5gj6ae7b6jeji.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%2Fi%2Fr525ecv5gj6ae7b6jeji.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fi%2Frh2qnjrhas7ezpubnej8.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%2Fi%2Frh2qnjrhas7ezpubnej8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Slice()
&lt;/h2&gt;

&lt;p&gt;Slice method doesn't change the original array. It is method of both arrays and strings. Slice method can take two arguments. First argument is required, second argument is optional.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First argument that represent where to start selection.&lt;/li&gt;
&lt;li&gt;Second argument that represent where to end selection.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&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%2Fi%2F35dm30ry5q6d4kzfbdg3.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%2Fi%2F35dm30ry5q6d4kzfbdg3.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fi%2Fwqhebpdx4ze238t2f7mw.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%2Fi%2Fwqhebpdx4ze238t2f7mw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Splice()
&lt;/h2&gt;

&lt;p&gt;Splice method changes the original array. It can remove element, replace existing elements, or add new elements to array. It can take 3+ arguments.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First argument is index and requried.&lt;/li&gt;
&lt;li&gt;Second argument is optional and represent the number of items be removed.&lt;/li&gt;
&lt;li&gt;Third argument is optional and represent the number of items be added. Argument can be increased.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes we want to remove items from array and we can use &lt;strong&gt;pop()&lt;/strong&gt; and &lt;strong&gt;shift()&lt;/strong&gt; methods instead of &lt;strong&gt;splice()&lt;/strong&gt; method. But it is easy to use and we can remove more than one item or add to the array.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 1
&lt;/h3&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%2Fi%2F0g2sms5wcf7nuggufei4.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%2Fi%2F0g2sms5wcf7nuggufei4.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fi%2Fi5t340tcq4ntdztg8cdy.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%2Fi%2Fi5t340tcq4ntdztg8cdy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 2
&lt;/h3&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%2Fi%2Fbqw2xvoigidz0koyenq3.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%2Fi%2Fbqw2xvoigidz0koyenq3.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fi%2F4qthp4d2wc5tj0tf630f.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%2Fi%2F4qthp4d2wc5tj0tf630f.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Split()&lt;/strong&gt; method is used for strings array, &lt;strong&gt;slice()&lt;/strong&gt; method is used for both arrays and strings. &lt;strong&gt;Splice()&lt;/strong&gt; method is used for only arrays.&lt;br&gt;
If you want to read more blog, you can check out my personal page.&lt;br&gt;
&lt;a href="https://syhnserkan.com/" rel="noopener noreferrer"&gt;https://syhnserkan.com/&lt;/a&gt;&lt;/p&gt;

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