我有一个数组,[],四个str,a,b,c,d,如果数组中有a就执行A,有b就执行B,有ab就执行AB,有几个执行几个,没有不执行,要怎么做
var arr = [a,b,c,d]
if(arr.indexOf('a')>-1){
console.log("a存在")
}
if(arr.indexOf('b')>-1){
console.log("b存在")
}
if(arr.indexOf('c')>-1){
console.log("c存在")
}
if(arr.indexOf('d')>-1){
console.log("d存在")
}
用循环
const arr = ['a', 'b', 'c', 'd'];
for (let i of arr) {
console.log(i);
}
var arry = [];
var a, b, c, d;
// ...
if (arry.indexOf(a) != -1) {
// Run A
}
if (arry.indexOf(b) != -1) {
// Run B
}
if (arry.indexOf(c) != -1) {
// Run C
}
if (arry.indexOf(d) != -1) {
// Run D
}