【发布时间】:2018-10-13 13:29:34
【问题描述】:
我有下面的对象
members
{
[
age:30,
list: [
"PRICE",
"LIST",
"COUNTRY"
]
]
},
{
[
age:31,
list: [
"PRICE"
]
]
},
{
[
age:31,
list: [
"LIST"
]
]
}
我需要检查数组值是否等于特定值。
我需要检查list 是否有PRICE 或list 是否有COUNTRY 或list 是否有PRICE,LIST,COUNTRY 组合。
目前我正在使用includes 检查值是否存在。但我需要检查确切的值
Array.isArray(members.list.map(message, index){
if(message.includes("LIST"))
{
}
if(message.includes("PRICE"))
{
}
if(message.includes("PRICE") && message.includes("LIST") && message.includes("COUNTRY"))
{
//message.includes("PRICE") and ("LIST") is already executed, so this will execute again. But i need to execute the complete condition combination.
}
})
如何做到这一点?
【问题讨论】:
-
Array.isArray(members.list.map(...))没有多大意义,因为.map()总是会返回一个数组 O.o -
查看这个帖子,对link有帮助
-
@Andreas 那么解决方案应该是什么?
-
先把比较变成最具体的,然后用else:
if(message.includes("PRICE") && message.includes("LIST") && message.includes("COUNTRY")) {} else if(message.includes("LIST")) {} else if(message.includes("PRICE")) { } -
@siraxtas 但该帖子未显示有关检查组合
标签: javascript arrays loops object conditional-statements