TypeScript 関数charAt()で文字列の先頭の文字を取得する

環境
Windows 11 Pro 64bit
TypeScript 4.4.4

構文
const 変数: string = 文字列.charAt(0)
charAt()の引数に「0」を指定します。
呼び出した文字列(string)の最初の文字を取得します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const tstr: string = "Study, TypeScript"
const res: string = tstr.charAt(0)
console.log(res)
const tstr: string = "Study, TypeScript" const res: string = tstr.charAt(0) console.log(res)
const tstr: string = "Study, TypeScript"

const res: string = tstr.charAt(0)

console.log(res)

実行結果
[LOG]: “S"

TypeScript

Posted by arkgame