Wildcard string comparison in Javascript

后端 未结 7 2174
花落未央
花落未央 2020-12-01 06:00

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

7条回答
  •  心在旅途
    2020-12-01 06:45

    if(mas[i].indexOf("bird") == 0)
        //there is bird
    

    You.can read about indexOf here: http://www.w3schools.com/jsref/jsref_indexof.asp

提交回复
热议问题