0

I have the following code, which i need to perform the javascript test() operation based on the var "p" value. The following sample doesn't resolve correctly. I know if i replace "p" with "hello", it will work, but i want it to resolve based on a particular value given in variable "p". How do i use variables along with the test() function? Please help.

var arr = new Array();
arr=[1,2,3,4,"hello"];
var p="hello";

if(/p/g.test(arr))
{
arr=arr.join('\n');
alert(arr); 
}

0 Answers0