TypeScript 配列をSetに変換するサンプル

環境
Windows 11 Pro 64bit
TypeScript 4.4.4

構文
const ttSet = new Set(配列名);
配列(array)をSetに変換するには、Set()を使います。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const array = [21, 32, 42, 43, 53, 43, 64, 75, 75];
const tSet = new Set(array);
console.log(tSet);
const array = [21, 32, 42, 43, 53, 43, 64, 75, 75]; const tSet = new Set(array); console.log(tSet);
const array = [21, 32, 42,  43, 53, 43, 64, 75, 75]; 

const tSet = new Set(array);

console.log(tSet);

実行結果
[LOG]: Set (7) {21, 32, 42, 43, 53, 64, 75}

TypeScript

Posted by arkgame