gpt4 book ai didi

javascript - 如何修复无效的解构分配目标?

转载 作者:行者123 更新时间:2023-12-04 17:37:03 25 4
gpt4 key购买 nike

我可以做什么来解决我的问题?我是 javascript 的新手,任何推荐或建议都可能对我有所帮助。

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);

如果代码工作正常,我应该取回一个包含新闻源的数组,但我却得到:无效的解构赋值目标

最佳答案

您写道:var user = { property }{ property }{ property } 这不起作用。这可能就是您的意思(也跳过了 var database = [ user ]; 赋值):

var database = [
{
username: "Andrey",
password: "JavaScript"
},
{
username: "Max",
password: "12345"
},
{
username: "Pasha",
password: "OWL"
};
]

关于javascript - 如何修复无效的解构分配目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56276514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com