admin管理员组

文章数量:1022769

for example i have an array like below:

[
    "May 30, 2015 12:00:00 AM", 
    "Jun 6, 2015 12:00:00 AM", 
    "Jun 13, 2015 12:00:00 AM", 
    "Jun 20, 2015 12:00:00 AM"
]

and i'd like to use replace() to convert all 12:00:00 AM is into empty so it bee

["May 30, 2015 ", "Jun 6, 2015", "Jun 13, 2015", "Jun 20, 2015"]

How may i do that?

for example i have an array like below:

[
    "May 30, 2015 12:00:00 AM", 
    "Jun 6, 2015 12:00:00 AM", 
    "Jun 13, 2015 12:00:00 AM", 
    "Jun 20, 2015 12:00:00 AM"
]

and i'd like to use replace() to convert all 12:00:00 AM is into empty so it bee

["May 30, 2015 ", "Jun 6, 2015", "Jun 13, 2015", "Jun 20, 2015"]

How may i do that?

Share Improve this question edited Jun 2, 2016 at 7:50 Mohammad 21.5k16 gold badges57 silver badges85 bronze badges asked Jun 2, 2016 at 7:10 Anson AşteptaAnson Aştepta 1,1432 gold badges14 silver badges39 bronze badges 2
  • Did you try anything ? What's the problem ? – Denys Séguret Commented Jun 2, 2016 at 7:11
  • you need this ? jsfiddle/atg5m6ym/5479 – Anoop Joshi P Commented Jun 2, 2016 at 7:14
Add a ment  | 

1 Answer 1

Reset to default 3

Use for to iterate array items and replace content of them.

var arr = [
    "May 30, 2015 12:00:00 AM", 
    "Jun 6, 2015 12:00:00 AM", 
    "Jun 13, 2015 12:00:00 AM", 
    "Jun 20, 2015 12:00:00 AM"
];

for (var i = 0; i < arr.length; i++) {
    arr[i] = arr[i].replace(" 12:00:00 AM", "");
}

console.log(arr);

for example i have an array like below:

[
    "May 30, 2015 12:00:00 AM", 
    "Jun 6, 2015 12:00:00 AM", 
    "Jun 13, 2015 12:00:00 AM", 
    "Jun 20, 2015 12:00:00 AM"
]

and i'd like to use replace() to convert all 12:00:00 AM is into empty so it bee

["May 30, 2015 ", "Jun 6, 2015", "Jun 13, 2015", "Jun 20, 2015"]

How may i do that?

for example i have an array like below:

[
    "May 30, 2015 12:00:00 AM", 
    "Jun 6, 2015 12:00:00 AM", 
    "Jun 13, 2015 12:00:00 AM", 
    "Jun 20, 2015 12:00:00 AM"
]

and i'd like to use replace() to convert all 12:00:00 AM is into empty so it bee

["May 30, 2015 ", "Jun 6, 2015", "Jun 13, 2015", "Jun 20, 2015"]

How may i do that?

Share Improve this question edited Jun 2, 2016 at 7:50 Mohammad 21.5k16 gold badges57 silver badges85 bronze badges asked Jun 2, 2016 at 7:10 Anson AşteptaAnson Aştepta 1,1432 gold badges14 silver badges39 bronze badges 2
  • Did you try anything ? What's the problem ? – Denys Séguret Commented Jun 2, 2016 at 7:11
  • you need this ? jsfiddle/atg5m6ym/5479 – Anoop Joshi P Commented Jun 2, 2016 at 7:14
Add a ment  | 

1 Answer 1

Reset to default 3

Use for to iterate array items and replace content of them.

var arr = [
    "May 30, 2015 12:00:00 AM", 
    "Jun 6, 2015 12:00:00 AM", 
    "Jun 13, 2015 12:00:00 AM", 
    "Jun 20, 2015 12:00:00 AM"
];

for (var i = 0; i < arr.length; i++) {
    arr[i] = arr[i].replace(" 12:00:00 AM", "");
}

console.log(arr);

本文标签: javascriptJQuery replace array value using replace()Stack Overflow