JSFiddle - React, Tailwind, and code Playground

JavaScript

var str = "1,2,3,4,5,6,7,8,9,10,2212312";
    var num = 7;

    //IndexOf
    var pieces = str.split(",");
    var index = pieces.indexOf(num.toString());
    alert(index!==-1);


    //regular expresison
    var re = new RegExp("(^|,)" + num + "($|,)");
    alert(re.test(str));