JavaScriptで文字列の文字を順番に取得する
Array.prototype.forEach.call()
を使うと、文字列の文字を順番に処理することができます。
call
により、文字列を配列っぽく扱ってくれます。
Array.prototype.forEach.call('hello world', (s) => {
console.log(s);
});
出力結果
> "h"
> "e"
> "l"
> "l"
> "o"
> " "
> "w"
> "o"
> "r"
> "l"
> "d"