不太确定如何为问题加上标题。尽管如此,请考虑以下陈述
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
}
如果问题措辞不佳,我们深表歉意,如有必要可以澄清。
谢谢!
最佳答案
您可以使用
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);
关于javascript - JavaScript-达到初遇的值(value),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46079315/