Sometimes, we want to convert a set to an array in TypeScript.
In this article, we’ll look at how to convert a set to an array in TypeScript.
How to convert a set to an array in TypeScript?
To convert a set to an array in TypeScript, we can set the downlevelIteration
option to true
in tsconfig.json
‘s compilerOptions
.
Then we can use the spread operator to convert sets to arrays.
For instance, we write
{
"compilerOptions": {
"downlevelIteration": true
}
}
to set the downlevelIteration
option to true
in our project.
Then we can use the spread operator on a set by writing
const arr = [...set];
to convert it to an array.
Conclusion
To convert a set to an array in TypeScript, we can set the downlevelIteration
option to true
in tsconfig.json
‘s compilerOptions
.
Then we can use the spread operator to convert sets to arrays.