Remove Elements from an Array Using slice ,Instead of splice

Remove Elements from an Array Using slice ,Instead of splice


Tell us what’s happening:
What I’m doing wrong here?

Your code so far

function nonMutatingSplice(cities) {
  // Add your code below this line
  var x = cities.slice(3,4);
  return x;
  // Add your code above this line
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:


It should start at 0 index. and then end after 3 items are added.


So i should write var x= cities.slice(0,3);right?


arr.slice(start, end)


The goal is to have your function ouput be

["Chicago", "Delhi", "Islamabad"]

Using your current code, it is:


Let’s say we were changing your slice to the following:


the output will be:


But we only want the first 3 cities.


Yes that must do it.


i rite that but tell me arr is not defined


This should work.
just add return x at end.


arr just means what ever array you have, in this case it would be ‘cities’

so… cities.slice(0,3);


Thank you for helping.


var x= cities.slice(0,3);
return x