1

I have a data set like this:

["[25.517202,55.555715]", "[25.517202,55.555715]", "[25.517202,55.555715]", "[25.517202,55.555715]", "[25.517202,55.555713]", "[25.51177,55.557574]", "[25.509928,55.557512]", "[25.509934,55.557521]"]

I want to change into the following:

[[25.517202,55.555715], [25.517202,55.555715], [25.517202,55.555715], [25.517202,55.555715], [25.517202,55.555713], [25.51177,55.557574], [25.509928,55.557512], [25.509934,55.557521]]

How to remove the " from the array return using react?

2 Answers 2

2

You can map the array with JSON.parse:

const array = ["[25.517202,55.555715]", "[25.517202,55.555715]", "[25.517202,55.555715]", "[25.517202,55.555715]", "[25.517202,55.555713]", "[25.51177,55.557574]", "[25.509928,55.557512]", "[25.509934,55.557521]"];

const parsed = array.map(JSON.parse);
console.log(parsed);

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

1 Comment

Hi, I have the result like 0: {id: 1,Name: "A"} 1: {id: 2,Name: "B"} 2: {id: 3,Name: "C"} 3: {id: 4,Name: "D"} 4: {id: 5,Name: "E"} 5: {id: 6,Name: "F"} 6: {id: 7,Name: "G"} I need below method [0,1] [2,3] [4,5] How we maks that @MorKadosh
0
const a=["[25.517202,55.555715]", "[25.517202,55.555715]", "[25.517202,55.555715]", "[25.517202,55.555715]", "[25.517202,55.555713]", "[25.51177,55.557574]", "[25.509928,55.557512]", "[25.509934,55.557521]"]

[...a].map(item=>JSON.parse(item))

Comments

Your Answer

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