Extract data from a javascript array

Asked

Viewed 473 times

2

I have an array, and in its contents it has a serialized value. I would like to separate these values and place each value in another array (with properly separated indexes). Follow my code:

data = ["["RibS7K/JS+ZTYtjDxqh5hg==","lO/CWn5lb3eqCkDhm9PpwA=="]", "["teste a","teste b"]", "[24351,24352]", "["png","png"]", "["teste a","teste b"]", "[7,6]", "[107.0,99.0]"]

newObject.idCrip = data[0];

When will I put in newObject.idCrip receives data[0], he gets ["RibS7K/JS+ZTYtjDxqh5hg==","lO/CWn5lb3eqCkDhm9PpwA=="] and not with two separate values and this is getting in my way. Any solution?

1 answer

3


I can’t say for sure because the code you posted is invalid (several quotes are missing), but I imagine you’re behind it here:

newObject.idCrip = JSON.parse(data[0]);

This works if you have that first array as string inside the array outside. Failed to convert to object.

Demonstration

  • I would simply like to withdraw the values of ["RibS7K/JS+ZTYtjDxqh5hg==","lO/CWn5lb3eqCkDhm9PpwA=="] to stay RibS7K/JS+ZTYtjDxqh5hg== and lO/CWn5lb3eqCkDhm9PpwA==

  • Have you tried what I suggested? It worked? It returns an array, with the first value at zero and the other at one.

  • It worked @bfavaretto! Thanks a lot!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.