【发布时间】:2020-06-13 18:26:28
【问题描述】:
嘿,我今天刚开始学习 javascript。
而且我在理解 else if 语句时遇到了一些麻烦。
我想如果第一个 if 语句为真,那么其他两个 else if 语句就不会被调用?
如果第一个 if 语句为 false,它会尝试第二个 else if 语句,如果第二个返回 false,它会尝试第三个 else if 语句?
但是所有的陈述都是真实的,我不知道为什么,希望有人能向我解释为什么?
var Builds = [
{ dead: 0, tier: 8, type: "Stash", uid: 9989, x: 4032, y: 11424 },
{ dead: 0, tier: 1, type: "Wall", uid: 9990, x: 4042, y: 11525 },
{ dead: 0, tier: 1, type: "Wall", uid: 9991, x: 4052, y: 11526 },
{ dead: 0, tier: 0, type: "Wall", uid: 9992, x: 4062, y: 11527 },
{ dead: 0, tier: 0, type: "Door", uid: 9993, x: 4072, y: 11428 },
{ dead: 0, tier: 0, type: "Door", uid: 9994, x: 4082, y: 11429 },
{ dead: 0, tier: 8, type: "Door", uid: 9995, x: 4092, y: 11430 },
{ dead: 0, tier: 1, type: "Gun", uid: 9996, x: 4100, y: 11431 }
];
Object.keys(Builds).filter(function(e) {
return ("Stash" == Builds[e].type || "Wall" == Builds[e].type || "Door" == Builds[e].type);
}).forEach(s => {
if (Builds[s].type == "Stash") {
console.log(Builds[s].type)
} else if (Builds[s].type == "Wall") {
console.log(Builds[s].type)
} else if (Builds[s].type == "Door") {
console.log(Builds[s].type)
}
})
对不起,如果我的英语不好。
【问题讨论】:
标签: javascript