我有这个对象:
combineLatest(
this.toppings.valueChanges.pipe(startWith(this.toppings.value)),
this.toppings2.valueChanges.pipe(startWith(this.toppings2.value)))
.subscribe(val => console.log(val))
(2) [Array(9), Array(2)]
0:(9) ["Douleur", "Psychologie", "Nutrition", "Social", "Rééducation physique", "Hygiène de vie", "Sexualité et fertilité", "Soins palliatifs", "Oncogériatrie"]
1:(2) ["CHU Nantes", "CH Le Mans"]
length:2
__proto__:Array(0)
我怎么能做一个像这样的条件? if ("CHU Nantes" is in the object val)
或if ("Douleur" or "Psychologie" is in the object val)
,所以......
我在结果中尝试这个:
if (val.includes("CHU Nantes")) {
CHUNantes.addTo(myfrugalmap);
} else {
CHUNantes.remove();
};
console.log(val);
您需要展平数组以搜索所有值。例如:val.reduce((acc, val) => acc.concat(val), []).includes("CHU Nantes");
对于现代浏览器,您也可以使用Array.prototype.flat:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat#Browser_compatibility