I am confused as how to get a value of an item from a data returned by axios function. I've looked at many examples, but only avail are returning value using map, such as below.
render() {
var student = this.state.student;
return (
student.map( d => (
..
<td>{d.grade}
..
);
)
But what I'm trying to do is store the value in a variable for manipulation. For example below, I want to extract the student grade:
class Student extends Component {
state = { student: [], };
componentDidMount() {
axio.get(window.$API_URL).then(res=>this.setState({stduent: res.data}));
var student = this.state.student;
var grade = student.grade; //** doesn't work
var grade = this.getGrade(student); //** doesn't work
var grade = getPropertyValue(student, "grade"); //** doesn't work
....
}
getGrade(student) {
student.map(d=>{return(d.grade)});
}
getPropertyValue(obj, dataToRetrieve) {
return dataToRetrieve
.split('.')
.reduce(function(o, k) {
return o && o[k];
}, obj)
}
render() { .... }
}