にそれらを保存します。JavaScriptを - 手紙に分割言葉と私はこのコードを持っている配列
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bad Grammar Generator</title>
</head>
<body>
<input type="text" id="userIn">
<input type="button" name="name" id="btn" value="Bad Grammar-ify" onclick="badgrammar()">
<span id="output"></span>
<script type="text/javascript">
var userIn = document.getElementById("userIn").value;
function badgrammar() {
var userIn = document.getElementById("userIn").value;
var output = document.getElementById("output");
var split = new Array();
split = userIn.split(" ");
output.innerText = split;
}
</script>
</body>
</html>
それは動作しますが、それは一つの単語にユーザー入力を分割します。どのように私はそれを文字にユーザー入力を分割することができますか?
例:
入力:Hi there
出力:H,i,t,h,e,r,e
'userIn.split(" ");'(スペースはありません)は個々の文字に分割されますが、スペースも除外したいと思うのですか? – smarx