Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Syntax
- // array.slice(start, end)
- // Parameter Description
- // start Index to start slicing (inclusive)
- // end Index to end slicing (exclusive) – optional
- // Returns New sliced array
- const fruits = ["apple", "banana", "cherry", "date", "fig"];
- const sliced = fruits.slice(1, 3);
- console.log(sliced); // ["banana", "cherry"]
- console.log(fruits); // ["apple", "banana", "cherry", "date", "fig"]
- // Omit end to slice to the end
- fruits.slice(2); // ["cherry", "date", "fig"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement