1

Example:

var imageBounds = [[40.712216, -74.22655], [46.773941, -79.12544]];

I need to create same from js. The problem that I am getting data in string format:

[40.712216, -74.22655], [46.773941, -79.12544]

so:

var mystr = "[40.712216, -74.22655], [46.773941, -79.12544]"

Ok, lets create empty array:

var myarr = []; // empty array

but how to add data to it? I know about push method but it's work only with arrays, and I have got text.

0

1 Answer 1

4

Make it valid JSON (by adding [ at beginning and ] at ending) afterward parse the string using JSON.parse method.

var mystr = "[40.712216, -74.22655], [46.773941, -79.12544]";

var res = JSON.parse('[' + mystr + ']');

console.log(res);

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

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.