이것은 나를 미치게합니다. 배열을 인쇄하려고하는데 작동하지 않습니다. 내가 뭘 놓치고 있니? 결과 변수는 "fordefined"를 반환하는데 이는 내 for 루프가 올바르게 작동하지 않는다는 것을 의미합니다. 다른 모든 것은 제대로 작동하는데, console.log 필드가 배열에 추가되었다는 것을 올바르게 표시했습니다. 자바 스크립트 : 배열을 통해 반복
// The list of accounts array.
var accountsArray = [];
function addAccount() {
// Take fields and put user data into varables.
var accountName = document.getElementById('accountName').value;
var accountBalance = document.getElementById('accountBalance').value;
var accountType = document.getElementById("accountType");
var accountTypeSelected = accountType.options[accountType.selectedIndex].text;
var accountCurrency = document.getElementById("accountCurrency");
var accountCurrencySelected = accountCurrency.options[accountCurrency.selectedIndex].text;
// Put these variables into the array.
accountsArray.push(accountName);
accountsArray.push(accountBalance);
accountsArray.push(accountTypeSelected);
accountsArray.push(accountCurrencySelected);
// Items added to the array, logged.
console.log('user added: ' + accountsArray);
}
function accountsListHtml() {
var results;
// Loop through the array
for (var i = 0; i < accountsArray.length; i++) {
results = accountsArray[i];
}
document.getElementById('accountsList').innerHTML = results;
}
각각 할당'결과 = accountsArray은 [I]는,'이라는 불필요한 어레이를 채우고 이전 – hindmost
'addAccount()을 ', 덮어 , 적어도 게시 한 코드에서. – Utkanos
@Utkanos HTML 'onclick'에서 호출됩니다. – jryankennedy