Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Delete a specific string in a `react` array

Hello I am importing value json .

console.log(value);
> Object Array(10)
 > 0
   imageUrl: "http://stackoverflow/images/0,"
 > 1
   imageUrl: "http://stackoverflow/images/1,"
 > 2
   imageUrl: "http://stackoverflow/images/2,"
 > 3
   imageUrl: "http://stackoverflow/images/3,"
 > 4 
   imageUrl: "http://stackoverflow/images/4,"
 > 5  
 
imageUrl:"http://stackoverflow/images/0http://stackoverflow/images/0,"

...
const Minsu = () => {
 
 return (
   <>
      <img src={value[0].imageUrl} />
   </>
 )

} 

My problem is that the image is not output properly because of this , in the imageUrl now, I want to delete only this string ‘,’.
However, I tried to delete only the ‘,’ string using filter, but it says that filter cannot be used because imageUrl is a string.

String I want to delete ‘,’ from a specific string, how can I do it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And if there are http://stackoverflow/images/0http://stackoverflow/images/0 in imageUrl, I want to delete one http.

>Solution :

Using replace() you can do it !

const arr = [
  { imageUrl: "http://stackoverflow/images/0," },
  { imageUrl: "http://stackoverflow/images/1," },
  { imageUrl: "http://stackoverflow/images/2," },
  { imageUrl: "http://stackoverflow/images/3," },
  { imageUrl: "http://stackoverflow/images/4," },
  { imageUrl: "stackoverflow/images/0http://stackoverflow/images/0, " },
]
function App() {
  return (
    <div>
      {arr.map(val => {
        return (
          <img src={val.imageUrl.replace(',', '').replace('stackoverflow/images/0', '')} />
        )
      })}
    </div>
  );
}

export default App;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading