var word = "Cell0";
//var char = word.stringCharAT();
for (i=0; i< word.length; i++) {
var pushWord = [];
pushWord.push(word[i]);
for (j=0; j< pushWord.length; j++) {
var reverseWord= [];
reverseWord = pushWord[j].pop;
console.log("reverseWord" + reverseWord);
}
}
答案 0 :(得分:0)
这是一个解决方案。
var word = "Cell0";
var reversed = '';
for (var i = word.length-1; i >= 0; i--) {
reversed += word[i];
}
console.log(reversed);
这将反向循环字符串的字符,并将字符添加到新字符串。
答案 1 :(得分:0)
pushWord[j]
不是数组,不会调用.pop
。
在pushWord
推送到reverseWord
之后,在for
循环之外定义word[i]
和pushWord
个数组,在.unshift()
上调用reverseWord
以pushWord[pushWord.length -1]
为参数的var word = "Cell0";
var pushWord = [];
var reverseWord = [];
for (let i = 0; i < word.length; i++) {
pushWord.push(word[i]);
reverseWord.unshift(pushWord[pushWord.length - 1]);
}
console.log("reverseWord" + reverseWord);
。
<div id="icon-bar">
<span class="searchbox-container">
<form class="searchbox">
<input type="search" placeholder="Search..." name="search" class="searchbox-input">
<button class="searchbox-button"><i id="search-icon" class="fa fa-search"></i></button>
</form>
</span>
</div>
&#13;
答案 2 :(得分:0)
var originalWord = "Cell0";
var reverseWord = [];
for (let i = 0; i < originalWord.length; i++) {
reverseWord.unshift(originalWord [i]);
}
console.log(reverseWord.join(''));
你甚至不需要推。 另一种实现结果的方法!