Ari Seyhun
Ari Seyhun

Reputation: 12531

Is it possible to modify a value in a Set

Using a JavaScript Set, is it possible to modify a value previously added?

For example:

const mySet = new Set()
mySet.add(42)

mySet.set(0, 69)

.set is made up, I just want to modify the set at index 0. Is there any way to do this or should I be using a regular array or even a Map?

Upvotes: 0

Views: 472

Answers (1)

jhpratt
jhpratt

Reputation: 7120

No, you have to remove it and readd the appropriate value. Sets only contain values, nothing more.

Sets don't have an index. You can use a Map or object, as you suggested.

Upvotes: 1

Related Questions