0

Here is my problem

const data = "[\"https://i.imgur.com/PAYXC2n.jpg\",\"https://i.imgur.com/bEfjjxA.jpg\"]";

I want to convert this string to array, expected result will be :

res =["https://i.imgur.com/PAYXC2n.jpg","https://i.imgur.com/bEfjjxA.jpg"]

I use it for mapping data in React JS project, so i need to convert this string to array.

1
  • 1
    @JuanMendes they did, but they forgot to format their code. Commented Jul 27, 2021 at 19:15

2 Answers 2

2

Just parse it from JSON:

const
  data = "[\"https://i.imgur.com/PAYXC2n.jpg\",\"https://i.imgur.com/bEfjjxA.jpg\"]",
  parsed = JSON.parse(data);

console.log(parsed);

Sign up to request clarification or add additional context in comments.

Comments

2

Do it: const dataArr = JSON.parse(data);. This will parse as to object, which is your array (With out "")

Comments

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.