0
私のコードでは、現在の要素を配列tmp
から文字列と数字の型で組み合わせようとしています。この比較では、異なる結果をコンソールに出力したい場合、つまり、同じ行(単語全体)に印刷する文字列、2行目にある次の単語などを印刷します。しかし、新しい行に印字する数字はすべて数字である。現在の変数と現在の変数を比較するにはどうすればよいですか?
出力数
入力文字列
出力文字列
HTML
<!Doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width">
<meta charset="utf-8">
<title>Exercises in JS</title>
<script src="exercises.js"></script>
<body>
<label for="myText">Input array:</label>
<input type="text" id="myText">
<a href="#" id="sub">Submit</a>
<br/>
<br/>
<label for="myText2">Input for delete:</label>
<input type="text" id="myText2">
<a href="#" id="sub2">Submit</a>
</body>
</head>
</html>
Javascriptを
window.onload = function(){
inputBox =document.getElementById("myText");
btn = document.getElementById('sub');
inputBox2 = document.getElementById("myText2");
btn2 = document.getElementById('sub2');
btn.addEventListener("click",function(event){
event.preventDefault();
saveArr(inputBox.value);
});
btn2.addEventListener("click",function(event){
event.preventDefault();
removeItemAndprintNewArray(inputBox.value, inputBox2.value);
});
function saveArr(arr) {
var rv = [];
for (var i = 0; i < arr.length; ++i)
rv[i] = arr[i];
return rv;
}
function removeItemAndprintNewArray(rv, number) {
var tmp = [],
st = "";
for(var index in rv){
if(rv[index] !== number){
tmp.push(rv[index]);
}
}
for (var i = 0; i < tmp.length; i++){
if (typeof(tmp[i]) == "String"){
st += tmp[i];
console.log(st);
}
else if (typeof(tmp[i]) === "Number"){
st += tmp[i];
console.log(st[i]);
}
}
}
}