Menu

gitpiper

frozenSet javascript Code Snippet in 2024

arrayintermediate

Last Updated: 3 November 2024

Creates a frozen Set object.

  • Use the new Set() constructor to create a new Set object from iterable.
  • Set the add, delete and clear methods of the newly created object to undefined, so that they cannot be used, practically freezing the object.
const frozenSet = iterable => { const s = new Set(iterable); s.add = undefined; s.delete = undefined; s.clear = undefined; return s; };
frozenSet([1, 2, 3, 1, 2]); // Set { 1, 2, 3, add: undefined, delete: undefined, clear: undefined }

javascript snippet similar to frozenSet For You in November 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️