How can I remove a part of each string in an array?
For example, an array like:
["u_img/5/16.png", "u_img/5/17.png", "u_img/5/19.png", "u_img/5/18.png"]
With u_img/5/ removed, the result:
["16.png", "17.png", "19.png", "18.png"]
Appreciate your help.
I think the Array.map() function should do what you want.
let original = ["u_img/5/16.png", "u_img/5/17.png", "u_img/5/19.png", "u_img/5/18.png"],
result = original.map(function(d) {
return d.replace('u_img/5/', '');
});
console.log(result); //["16.png", "17.png", "19.png", "18.png"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With