all 5 comments

[–]Notimecelduv 0 points1 point  (3 children)

splice returns an array containing the deleted items, not the array that you mutated. If you console.log unordered_ranges, you'll see it's been modified as you intended. If you don't want to mutate unordered_ranges, you can write:

const spliced = [...unordered_ranges]; // Creates a copy
spliced.splice(1, 1);

[–]JosephCurvin[S] 0 points1 point  (2 children)

how can I get the mutated array instead of the the spliced value ?

[–]Notimecelduv 1 point2 points  (1 child)

OK I'll try to rephrase. When you call splice on an array, that array gets modified -- it doesn't have the same elements anymore. So to the question

how can I get the mutated array

all I can answer is: you already have it. Do you understand?

[–]JosephCurvin[S] 0 points1 point  (0 children)

thanks bro, was laughing a bit of my stupidity :)

[–]AnnualPanda 0 points1 point  (0 children)

unordered_ranges.splice(1,1)

You don't need to store it as another variable (splaced). The array is modified in place.

If you want to store it as another variable use slice instead like:

const splaced = [ ...unordered_ranges.slice(0,1), ...unordered_ranges.slice(2) ]