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
1 Answer
Reset to default 3Use 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
1 Answer
Reset to default 3Use 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
版权声明:本文标题:javascript - JQuery: replace array value using .replace() - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745544439a2155330.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论