why (0,3) when i am supposed to return only 3 cities?? Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function nonMutatingSplice(cities) {
// Only change code below this line
return cities.slice(0, 3);
// Only change code above this line
}
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);
console.log(inputCities)
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0
Challenge: Remove Elements from an Array Using slice Instead of splice
Take a close look at the docs for the slice method.
Carefully read through the explanation for the optional end parameter from the docs.
Zero-based index before which to end extraction. slice extracts up to but not including end . For example, slice(1,4) extracts the second element through the fourth element (elements indexed 1, 2, and 3).
So in your case here
the slice method will start and index 0 and include 1 and 2 but not 3.
Also, this console.log is just returning the original array
But remember that slice creates a new array.
If you want to see your results in the console, place the console.log inside your function.