0

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?

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

2 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

4 Comments

Since imageurl is stackoverflow/images/0http://stackoverflow/images/0, I want to delete only this part of http://stackoverflow/images/0. What should I do?
Update my answer !
If my answer helps you accept it :)
Oh, thank you! But Array 6 7 8 .. is also getting different http://stackoverflow/images/1, 3, 4 ... output. i think i need to cut this http
1

Try replace

const value = [{ imageUrl: 'http://stackoverflow/images/0,' }];
export default function App() {
  return (
    <div>
      <h1>Hello StackBlitz!</h1>
      <p>Start editing to see some magic happen :)</p>
      return (
      <>
        <img src={value[0].imageUrl.replace(',', '')} />
      </>
      )
    </div>
  );
}

1 Comment

Since imageurl is stackoverflow/images/0http://stackoverflow/images/0, I want to delete only this part of http://stackoverflow/images/0. What should I do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.