Hey folks, in this thread we'll learn about the slice method in arrays in Javascript.
It is one of the most widely used methods and is among my personal favorites.
Let's begin! 👇
It is one of the most widely used methods and is among my personal favorites.
Let's begin! 👇
✂️ Array.slice() method is no different, only instead of mangoes, we're cutting an array.
⬅️ So, when we want to get data out of an array without disturbing the original array, we use Array.slice().
📍 Notice the 'without disturbing' part. it is important for immutability.
⬅️ So, when we want to get data out of an array without disturbing the original array, we use Array.slice().
📍 Notice the 'without disturbing' part. it is important for immutability.
🚀 And immutable data operation is a key part of Functional programming but more on that later.
🌟 Let's switch back to our slicing action on arrays & take a look at its fairly simple syntax.
👇 The general syntax is as follows:
🧩 arrayName.slice( indexFrom, indexTo )
🌟 Let's switch back to our slicing action on arrays & take a look at its fairly simple syntax.
👇 The general syntax is as follows:
🧩 arrayName.slice( indexFrom, indexTo )
🗃️ Here,
✅ arrayName = the name of the array we're calling this function on,
✅ indexFrom = the index in the array from which to start slicing, and
✅ indexTo = the index till which to slice.
✅ Array.slice() then returns a sub-array of corresponding elements.
✅ arrayName = the name of the array we're calling this function on,
✅ indexFrom = the index in the array from which to start slicing, and
✅ indexTo = the index till which to slice.
✅ Array.slice() then returns a sub-array of corresponding elements.
That's a wrap!
Hey, I write two threads every day on web dev and it takes a lot of time and effort.
So, I'd be glad if you could spare me a minute to:
✅ Follow me @sumitsaurabh927 for more of these.
✅ RT the tweet below to show me some love.
Hey, I write two threads every day on web dev and it takes a lot of time and effort.
So, I'd be glad if you could spare me a minute to:
✅ Follow me @sumitsaurabh927 for more of these.
✅ RT the tweet below to show me some love.
Loading suggestions...