admin管理员组文章数量:1332383
If my array is gave me:
["ITEM_1", "ITEM_2", "ITEM_3"]
How I can remove the part ITEM_
to get only ["1", "2", "3"]
?
If my array is gave me:
["ITEM_1", "ITEM_2", "ITEM_3"]
How I can remove the part ITEM_
to get only ["1", "2", "3"]
?
-
1
["ITEM_1", "ITEM_2", "ITEM_3"].map(e => e.replace('ITEM_', ''))
– Nenad Vracar Commented Apr 2, 2017 at 19:29 - You can use regex to extract number developer.mozilla/fr/docs/Web/JavaScript/Guide/… – Incognito Commented Apr 2, 2017 at 19:29
- @qatari, do you want to modify the initial array? – RomanPerekhrest Commented Apr 2, 2017 at 20:14
2 Answers
Reset to default 3or:
var arr = ["ITEM_1", "ITEM_2", "ITEM_3"].map(function(item){
return item.split('_')[1];
});
or:
var arr = ["ITEM_1", "ITEM_2", "ITEM_3"].map(function(item){
return item.replace('ITEM_', '');
});
You could do:
console.log(
["ITEM_1", "ITEM_2", "ITEM_3"].join().match(/\d+/g)
)
本文标签: How to replace all occurrences of an array in JavaScriptStack Overflow
版权声明:本文标题:How to replace all occurrences of an array in JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742296536a2448843.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论