Saturday 8 April 2017

How do I convert a JSON string into and an array of unknown objects?

I'm creating a simple flashcard generator and have a JSON String containing multiple arrays and objects that looks like this:

data = [{"front":"What is your name?","back":"Billy"},{"front":"How old are you?","back":"40"}][{"front":"Is this a test?","back":"yes"}]

When I console.log(data.length) i get 130.

I can enter more than one flashcard at a time, and can enter the flashcards at any given time. That's why there's the ][ are in the middle of it.

I'm trying to loop through said array and end up with something along the lines of:

data = [{"front":"What is your name?","back":"Billy"},{"front":"How old are you?","back":"40"},{"front":"Is this a test?","back":"yes"}]

Where console.log(data.length) = 3

And eventually data[i].front = "What is your name?"

Can someone please put me in the right direction? The data is being read from a txt file if that makes a difference.



via IsaacWIvins

No comments:

Post a Comment