we use Array.splice() to get the part of spliced, I wonder how I can get the remained part, without create another variable and let it = Array.splice().
Your code so far
const arr = [2, 4, 5, 1, 7, 5, 2, 1];
// Only change code below this line
// Only change code above this line
Your browser information:
User Agent is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36
Challenge: Remove Items Using splice()
Link to the challenge:
splice returns the removed element, so the output of splice is the spliced ones, the mutated array is what is not unspliced
splice work - if you don’t want to mutate
arr you need to use other methods
Yep, what I mean is how I can get the remained part, you have any idea?
const arr = [1,2,3,4,5,6,7]
const removed = arr.splice(1, 4)
console.log(removed); //array with the removed elements
console.log(arr); // array with remaining elements
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.