DEV Community

loading...

What does slice do with no arguments?

whataluckyguy profile image Lalit Kumar ・1 min read

The slice() function method returns a copy of a section of an array or string into a new array or string object selected from start to end. The terms start and end represents the index value of the items in that array or string. Although the original array or the string will not be modified. slice() function simply copies the items into the new returned array or the string.

The syntax of using slice() in an array is arr.slice(start, end)
By looking at the syntax of the slice() function, we can understand that we have to provide the starting and ending index of the elements to select the portion.
The first element has index 0 and if we want to start selecting from the end then we can use negative numbers. But the main question of this article was what if we use slice() function with no arguments in it?

What does slice do with no arguments?

Read more

Discussion

pic
Editor guide