Compare part of string in JavaScript

后端 未结 7 2081
感动是毒
感动是毒 2020-12-31 01:12

How do I compare a part of a string - for example if I want to compare if string A is part of string B. I would like to find out this: When string A = \"abcd\"

7条回答
  •  滥情空心
    2020-12-31 01:45

    Javascript ES6/ES2015 has String.includes(), which has nearly all browser compatibility except for IE. (But what else is new?)

    let string = "abcdef";
    string.includes("abcd"); //true
    string.includes("aBc"); //false - .includes() is case sensitive
    

提交回复
热议问题