TypeScriptでリストやタプルを指定するサンプル

2021年11月20日

環境
Windows10 64bit
Typescript 4.4.4
書式
let 配列名: string[] =[xxx]
let リスト名: Array<string> = [xxx]

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
//配列
let cftA: string[] = ["study", "Skill", "Strong","arkgame"];
//リスト
let cftB: Array<string> = ["study", "Skill", "Strong","arkgame"];
//タプル
let cftC: [string, number] = ["山田太郎", 34];
console.log("配列を指定する")
cftA.forEach(element => console.log(element));
console.log("リストを指定する")
cftB.forEach(element => console.log(element));
console.log("タプルを指定する")
console.log(cftC);
//配列 let cftA: string[] = ["study", "Skill", "Strong","arkgame"]; //リスト let cftB: Array<string> = ["study", "Skill", "Strong","arkgame"]; //タプル let cftC: [string, number] = ["山田太郎", 34]; console.log("配列を指定する") cftA.forEach(element => console.log(element)); console.log("リストを指定する") cftB.forEach(element => console.log(element)); console.log("タプルを指定する") console.log(cftC);
//配列
let cftA: string[] = ["study", "Skill", "Strong","arkgame"];
//リスト
let cftB: Array<string> = ["study", "Skill", "Strong","arkgame"];
//タプル
let cftC: [string, number] = ["山田太郎", 34];

console.log("配列を指定する")
cftA.forEach(element => console.log(element));
console.log("リストを指定する")
cftB.forEach(element => console.log(element));
console.log("タプルを指定する")
console.log(cftC);

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
>tsc
>ts-node arkgame.js
配列を指定する結果
study
Skill
Strong
arkgame
リストを指定する結果
study
Skill
Strong
arkgame
タプルを指定する結果
[ '山田太郎', 34 ]
>tsc >ts-node arkgame.js 配列を指定する結果 study Skill Strong arkgame リストを指定する結果 study Skill Strong arkgame タプルを指定する結果 [ '山田太郎', 34 ]
>tsc
>ts-node arkgame.js
配列を指定する結果
study
Skill
Strong
arkgame
リストを指定する結果
study
Skill
Strong
arkgame
タプルを指定する結果
[ '山田太郎', 34 ]

 

TypeScript

Posted by arkgame