現在、私は角度2.0を使用しています。配列にtypescriptの文字列が含まれているかどうかを確認するには?
channelscrayに文字列 'three'が含まれているかどうかをチェックするにはどうすればよいですか?
現在、私は角度2.0を使用しています。配列にtypescriptの文字列が含まれているかどうかを確認するには?
channelscrayに文字列 'three'が含まれているかどうかをチェックするにはどうすればよいですか?
jsのと同じで、 indexOf()を使用して
console.log(channelArray.indexOf("three") > -1);
またはES6 Array.prototype.includesを使用して()
console.log(channelArray.includes("three"));
あなたはsome methodを使用することができます。
console.log(channelArray.some(x => x === "three")); // true
あなたはfind methodを使用することができます。
console.log(channelArray.find(x => x === "three")); // three
それともindexOf methodを使用することができます。
console.log(channelArray.indexOf("three")); // 2
それは 'channelArrayする必要があります:文字列の[]' –
可能な重複配列は、JavaScriptでのオブジェクトが含まれている場合は、[どのようにしてチェックしますか? ](http://stackoverflow.com/questions/237104/how-do-i-check-if-an-array-includes-an-object-in-javascript) –