Today we discuss Pop and other methods:
Let’s apply our knowledge again 💪
Array.prototype.pop removes the last element of Array in JS.
Since TypeScript 4.2 we can use rest elements not only at the very last position of a tuple type.
We will infer all elements but the last and return them as result:
Array.prototype.push adds the element to the end of Array in JS.
We spread all elements we have and add the pushed element to the end:
Array.prototype.shift removes the first element of Array in JS.
So we need to infer all elements but the first one and return them as result:
Array.prototype.unshift adds the element to the beginning of Array in JS.
We spread all elements we have and add unshifted element to the beginning:
We just applied spread in different manipulations with tuples.
If you’re interested with examples, please have a look at Playground
Have a good evening ☁️ and nice weekend 💃🕺!typescriptmedium