I am new in javascript. It may be a basic thing but I am stuck with it. here is my json:
{
"statusCode": 200,
"status": "success",
"data": [
[
{
"city": "Alexandria",
"country": "Egypt",
},
{
"city": "Alexandria",
"country": "Egypt",
},]]
I want to access this:
0: {city: "Alexandria", country: "Egypt"}
1: {city: "Antalya", country: "Turkey"}
I tried this code :
getData = function (data) {
keys = Object.keys(data[0]);
data = [];
keys.forEach(function (key) {
data.push(key);
});
return data;
}
which returns this:
0: "0"
1: "1"
2: "2"
3: "3"
4: "4"
5: "5"
6: "6
please help me!
obj.data[0]will give you your array