0

Here is the code

location: '["41.8481","-72.0345"]'

Here is what I tried

location.replace(/'/g,'');

This is what I want

location: ["41.8481","-72.0345"]

Any help would be appreciated

3
  • You want to convert the string to an array? Commented Apr 30, 2022 at 5:01
  • I want this location: ["41.8481","-72.0345"] Commented Apr 30, 2022 at 5:02
  • Got it check my answer below, it has a working snippet as well! Commented Apr 30, 2022 at 5:04

2 Answers 2

2

You can parse the string to an array using JSON.parse

const loc = '["41.8481","-72.0345"]';
const locArr = JSON.parse(loc);
console.log(locArr);

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

Comments

1

You can parse to get the desired solution

JSON.parse(location)

2 Comments

Thank you! Someone updated their answer to match yours, but I know who helped me.
Make it to green if its right... It would help others... Cheers!

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.