user270158
user270158

Reputation: 441

javascript replace

i want to replace month name by number in array, but my script doesnt work.

for(i=0; i<a.length; i++) {
arr = arr.replace(/Jan/g, "01");
}

Can somebody help me please?

Upvotes: 1

Views: 242

Answers (3)

fire
fire

Reputation: 21531

for(i=0; i<a.length; i++) {
  a[i] = a[i].replace(/Jan/g, "01");
}

Upvotes: 0

curv
curv

Reputation: 3844

Try this:

for(i=0; i<a.length; i++) { 
    arr[i] = arr[i].replace(/Jan/gi, "01"); 
} 

Also... Shouldn't the line be:

for(i=0; i < arr.length; i++) {

Upvotes: 1

kgiannakakis
kgiannakakis

Reputation: 104168

Perhaps you need:

arr[i] = arr[i].replace(/Jan/g, "01");

Upvotes: 6

Related Questions