對於這個非常新手的問題,我很抱歉,但這讓我很生氣。從並行數組中返回一個字符串
我有一個詞。對於單詞的每個字母,找到一個數組中的字符位置,然後將該字符返回到並行數組(基本密碼)中找到的相同位置。這是我已經有:
*array 1 is the array to search through*
*array 2 is the array to match the index positions*
var character
var position
var newWord
for(var position=0; position < array1.length; position = position +1)
{
character = array1.charAt(count); *finds each characters positions*
position= array1.indexOf(character); *index position of each character from the 1st array*
newWord = array2[position]; *returns matching characters from 2nd array*
}
document.write(othertext + newWord); *returns new string*
我的問題是,在目前的功能只寫出來的新詞的最後一個字母。我希望在document.write中添加更多的文本,但是如果我放在for循環中,它會寫出新的單詞,但也會寫出每個單詞之間的其他文本。我真正想要做的是返回othertext + newWord而不是document.write,以便稍後使用它。 (只是使用doc.write文本我的代碼):-)
我知道它的東西很簡單,但我不知道我哪裏去錯了。有什麼建議? 由於 伊西
嗨伊西,歡迎來到SO。不幸的是,如果大多數用戶對「家庭作業」風格的問題有些嗤之以鼻,他們很可能不會迴應。此外,這是什麼語言? – Ben 2011-05-14 08:31:08
史蒂夫,謝謝你的回覆,是的,我知道它很難,我真的想爲自己工作,但我只是需要一個正確的方向,因爲我完全卡在哪裏去。它在JavaScript中。謝謝Issy – user753420 2011-05-14 08:50:58