我可以做些什么来解决我的问题?我是一个新的JavaScript新手和任何recomendations或建议可能对我有帮助。
var user = {
username: "Andrey",
password: "JavaScript"
},
{
username: "Max",
password: "12345"
},
{
username: "Pasha",
password: "OWL"
};
var database = [user];
var newsfeed = [
{
username: "Bobby",
timeline: "DOOOOOOG!",
},
{
username: "Max",
timeline: "CAAAAT!",
},
{
username: "Lida",
timeline: "John Ceeeenaaaa!",
}
];
var userNamePrompt = prompt("Your Username?");
var passwordPrompt = prompt("Your password?");
function isUserValid(Name, Pass){
for (var i=0; i<database.length; i++){
if (database[i].username === Name &&
database[i].password === Pass) {
return true;
}
}
return false;
}
function SignIn (Name, Pass){
if (isUserValid(Name, Pass)) {
console.log(newsfeed);
}
else {
alert("Sorry smt went wrong!");
}
}
SignIn (userNamePrompt, passwordPrompt);
如果代码工作正常,我应该得到一个带有newsfeed的数组,但我得到的是:无效的解构分配目标
1条答案
按热度按时间gt0wga4j1#
你写的是:
var user = { property }{ property }{ property }
,它不起作用。这可能就是你的意思(也跳过了var database = [ user ];
赋值):