I'm trying to convert a JSON string into an array containing the values from the JSON. When I use json.stringify(jsonmybe)
and alert it, I see
[{"role":"noi_user"},{"role":"bert_user"}]
(which is in JSON format). My goal is to extract `noi_user` and `bert_user` and save them in a JavaScript array like ['noi_user','bert_user']
, with quotes around each value.
After using var stringy = json.parse()
and displaying the alert, I only see [object Object]
. So, I added the following lines:
for (var i = 0; i < stringy.length; i++) {
arr.push(stringy[i]['role']);
}
In the alert, I see `arr` as a single value with a comma missing between them. When displayed in a text field, it appears as one long string like noi_userbert_user
.
Ultimately, I want to transform
[{"role":"noi_user"},{"role":"bert_user"}]
into ['noi_user','bert_user']
.