4

How can I convert the following data structure:

var data = [ [ { time: 1, speed : 20 } ] ]; 

to

var data = [ { time: 1, speed: 54 } ];

I just want to remove the array.

2 Answers 2

20

As the data is an array, you just want to select the first element of the outer array

so the solution would be

var data = [[{time:1,speed:20}]]; // Or whatever the data is
data = data[0];

Or if you're accessing the data via another object

var data = yourObject[0];
Sign up to request clarification or add additional context in comments.

Comments

3

Try this :

JSON.stringify(data).substr(1,JSON.stringify(data).length-2);

1 Comment

i wanted to remove the { and } from the object and this was a valid solution

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.