0

I learn this Array prototype slice

This is what I tried:

const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];

console.log(animals.slice(1, 2));
//outputs: ["bison"]

Why is this not outputting ["bison", "camel"] since the doc state it's a zero because operation?

enter image description here

0

2 Answers 2

1

The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument.

More info here.

Sign up to request clarification or add additional context in comments.

1 Comment

"but does not include, the given end argument." , Strange why not make it so; console.log(animals.slice(1, 1));
1

the end is not included more info

The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.