To do this, you can use the regular expression:
/(^|,)1(,|$)/.test("2,1,4,5") // => true
just check the negative case
/(^|,)1(,|$)/.test("2,11,4,5") // => false
If you have a multi-line string (containing \r\n), use /(^|,)1(,|$)/minstead
source
share