【发布时间】:2018-12-02 23:32:55
【问题描述】:
我试过摆弄代码,这是我完成我想要的最接近的事情。截至目前,它重写了 index[0],保留 index[1] 不变,并添加了 index [2]。我正在尝试让它保持 index[0] 和 index[1] 不变,只需添加新索引。
// Store all accounts and information
var account = [
{
username: "John Sant",
password: "dog123",
balance: 450
},
{
username: "Rebecca Dunson",
password: "Munco38",
balance: 1276
}
]
// Create new user or proceed to sign in
var task = prompt("Do you have an account? (Yes or No)")
if(task.toLowerCase() === "no"){
for(i = 0; i <= account.length; i++){
var newUsername = prompt("Enter your first and last name:")
account[i++] = {username: newUsername}
};
}
现在只关注用户名
【问题讨论】:
标签: javascript arrays object indexing