1

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?

0

3 Answers 3

6

Perhaps you need:

arr[i] = arr[i].replace(/Jan/g, "01");
Sign up to request clarification or add additional context in comments.

Comments

1

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++) {

1 Comment

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.