Array.prototype.toggle

Herby Vojčík herby at mailbox.sk
Fri Feb 7 19:26:44 UTC 2020


On 7. 2. 2020 13:11, Scott Rudiger wrote:
> `Array.prototype.filter` seems more versatile (although it doesn't 
> mutate the original array) since it removes elements based on a function:
> 
> ```js
> [1, 2, 3, 2, 1].filter(n => n !== 1); // [2, 3, 2]
> ```

But what if one wants to mutate in-place. Would this work?

   Object.assign(arr, arr.filter(n => n !== 1))

If not, maybe there can be

   aCollection.replaceWith(anIterable)

Herby


More information about the es-discuss mailing list