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?
asked Feb 12, 2010 at 11:09
user270158
4412 gold badges5 silver badges10 bronze badges
3 Answers 3
Perhaps you need:
arr[i] = arr[i].replace(/Jan/g, "01");
Amber
532k89 gold badges643 silver badges558 bronze badges
answered Feb 12, 2010 at 11:11
kgiannakakis
104k28 gold badges163 silver badges197 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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++) {
answered Feb 12, 2010 at 11:12
curv
3,8444 gold badges35 silver badges48 bronze badges
1 Comment
curv
Also note.. /Jan/gi Not /Jan/g
for(i=0; i<a.length; i++) {
a[i] = a[i].replace(/Jan/g, "01");
}
answered Feb 12, 2010 at 11:26
fire
21.5k18 gold badges82 silver badges116 bronze badges
Comments
lang-js