不确定如何标题。尽管如此 - 请考虑您有以下声明
if (messageOne || messageTwo || messageThree || messageFour) {
// do something here ...
}
你会如何抓住并使用得到满足的信息?例如
if (messageOne || messageTwo || messageThree || messageFour) {
console.log(messageOne) // <-- but rather than hardcoding messageOne I want to be able to grab whichever one is executed
}
如果问题措辞不当,请道歉,如有必要可以澄清。
谢谢!
答案 0 :(得分:6)
你可以使用
let result = messageOne || messageTwo || messageThree || messageFour;
let messageOne = null;
let messageTwo = null;
let messageThree = null;
let messageFour = "4";
let result = messageOne || messageTwo || messageThree || messageFour;
console.log(result);
&#13;