Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove part of each string in array

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.


1 Answers

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"]
like image 137
Joe Beuckman Avatar answered Jan 20 '26 08:01

Joe Beuckman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!