Output from:
console.log(response);
console.log(response[0].group_id);
is as below:
[{"group_id":8}]
undefined
what is wrong here? How do I access the value for "group_id" i.e. 8
Possibly the content in response is a string and not a JSON object.
I suggest to parse the object using JSON, like so:
const o = JSON.parse(response);
console.log(o[0]);
console.log(o[0].group_id);
What you suggested (response[0].group_id) definitely should return 8 in case response is a JSON object. If you try this code below:
const o = JSON.parse("[{\"group_id\":8}]");
console.log(o[0]);
console.log(o[0].group_id);
You will get this output:
{ group_id: 8 }
8
console.log(typeof response). If it returns "string" it means that response is not an json object but a regular string.