nwaps
nwaps

Reputation: 11

js match serarching with array

I'm trying to get the first date of each 3 names from a list sorted by rows. The array is dynamic. Without arrays, it works fine...

But from here I can't get it to work. Is there any way to get the array into the match?

var array=new Array();
array[1]='name1';
array[2]='name2';
array[3]='name3';

for (var k = 1; k <= array.length; k++) {
    tow = document.getElementById('cal_table');
    zap = tow.getElementsByTagName('tr');

    for (var i=1; i<=zap.length; i++){
        opt0 = zap[i].innerHTML.match(/<td>array[k]<\/td>|<td>.*2012<\/td>/img);
        if(opt0.length==2){
            alert(opt0);
            break
        }
    }
}

Upvotes: 0

Views: 131

Answers (1)

Steve Wang
Steve Wang

Reputation: 1824

You have to use the RegExp constructor, i.e. new RegExp("<td>" + array[k] + "|<td>.*2012<\/td>", "img").

Upvotes: 2

Related Questions