12/5/2023 0 Comments Javascript setLet sentence = new Set('Only unique characters will be in this set.') Strings are a valid iterable so they can also be passed-in to initialize a set: console.log('Only unique characters will be in this set.'.length) // 43 Notice how the initializing array gets deconstructed, but an array added added later stays in the form of an array: let myAnimals = new Set() Here’s another example where we pass-in an array to initialize the set. ![]() Here’s a simple example showing off a basic set and a few of the available methods on it like add, size, has, forEach, delete and clear: let animals = new Set() The values in a set can be either simple primitives like strings or integers as well as more complex object types like object literals or arrays. Sets are a new object type with ES6 (ES2015) that allow creating collections of unique values.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |