As a beginner in javascript, I am facing an issue that may seem basic to others. Here is the json data I am working with:
{
"statusCode": 200,
"status": "success",
"data": [
[
{
"city": "Alexandria",
"country": "Egypt",
},
{
"city": "Alexandria",
"country": "Egypt",
},]]
My goal is to access specific elements within this data:
0: {city: "Alexandria", country: "Egypt"}
1: {city: "Antalya", country: "Turkey"}
I have attempted the following code snippet:
getData = function (data) {
keys = Object.keys(data[0]);
data = [];
keys.forEach(function (key) {
data.push(key);
});
return data;
}
However, the output of this code is not what I expected. It returns:
0: "0"
1: "1"
2: "2"
3: "3"
4: "4"
5: "5"
6: "6
If anyone could provide assistance or guidance on how to resolve this issue, it would be greatly appreciated!