Basic Data Structures - Copy Array Items Using slice()

Tell us what’s happening:
Describe your issue in detail here.
I don’t understand how the 2nd parameter of .slice method works can someone explain it, I thought it should be 2,3 but for some reason 2,4 works?
Your code so far

function forecast(arr) {
  // Only change code below this line

  return arr.slice(2,4);
}

// Only change code above this line
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));

Your browser information:

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

Challenge: Basic Data Structures - Copy Array Items Using slice()

Link to the challenge:

From the MDN article https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice:
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)

Ah I m an idiot it was written there, thank you.

Eh, please don’t feel like idiot. It takes time to get a grasp on all these nuances about new methods

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.