Wildcard string comparison in Javascript

2020-01-30 07:15发布

Let's say I have an array with many Strings Called "birdBlue", "birdRed" and some other animals like "pig1", "pig2").

Now I run a for loop that goes through the array and should return all birds. What comparison would make sense here?

Animals == "bird*" was my first idea but doesn't work. Is there a way to use the operator * (or is there something similar to use?

7条回答
Melony?
2楼-- · 2020-01-30 08:09

Instead Animals == "bird*" Animals = "bird*" should work.

查看更多
登录 后发表回答