I am having issues searching for a variable within a variable. The code that I have is:
var str = "13, 12, 12, 12";
//Look for string = 13 in str.
var string = 13;
var patt = "/" + string + "/g";
var result = patt.test(str);
What is my error?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
to build your pattern. The
/something/gconstruct cannot be used for dynamic patterns.See MDN’s documentation on regular expressions.