I have a jsx
file with code
var React = require('react');
var CreateReactClass = require('create-react-class');
var url = "192.168.1.1:8081/json";
let data = [];
fetch(url)
.then(response => response.json())
.then(result => data.push(result));
console.log(data);
console.log(data[1].name);
console.log(data); returns data but I can't seem to get any specific attributes out from it. console.log(data[1].name); just returns: TypeError: data[1] is undefined.
on the URL address I have json
[
{
"id": "2",
"name": "led",
"color": "blue"
},
{
"id": "3",
"name": "le",
"color": "red"
}
]
for some reason the length of my data array is 0 even after pushing json data into it.
How can I get console to log an attribute from data variable like "name":"le"
.