Reactjs 无法从react中的对象数组中提取值

Reactjs 无法从react中的对象数组中提取值,reactjs,redux,axios,Reactjs,Redux,Axios,我有一个React项目,从API返回一个对象数组。成功将此对象数组设置为类组件中的状态后,我想使用特定值,例如: 我回来了[{bar:2,foo:13},{bar:22,foo:3},{bar:9,foo:1}] 然后我想说把2从杆上拔下来:2 虽然我可以拉出特定的对象,例如{bar:2,foo:13},但我不能拉出bar或foo class App extends Component { constructor(props) { super(props); this.state =

我有一个React项目,从API返回一个对象数组。成功将此对象数组设置为类组件中的状态后,我想使用特定值,例如:

我回来了[{bar:2,foo:13},{bar:22,foo:3},{bar:9,foo:1}]

然后我想说把2从杆上拔下来:2

虽然我可以拉出特定的对象,例如{bar:2,foo:13},但我不能拉出bar或foo

class App extends Component {
constructor(props) {
 super(props);

   this.state = {
   videos: []
  };
 }


componentDidMount() {
axios
  .get("https://abc.herokuapp.com/videos/videoapi")
  .then(response => response)   
  .then(data => this.setState({ videos: data.data}));
}

render() {
const videos = this.state.videos;
console.log(videos); //returns array with 4 objects 
console.log(videos[0]); //returns object with 6 properties
console.log(videos[0].embed); //TypeError: Cannot read property 'embed' of 
undefined

这是否只是一个异步问题,因为在跳入之前没有检查
this.state.videos.length>0
?是否
console.log(videos[0])返回对象或字符串?您可能需要
JSON.parse(视频[0])
。检查
typeof(videos[0])
,etcThanks,结果是一个异步问题,通过检查长度得到修复。然而,我不确定我是否完全理解。看起来,如果我能够对整个对象进行console.log,我应该不会有任何困难提取单个属性。这可能是因为您混合了来自不同渲染的日志。在第一次渲染中,
videos[0]
未定义的
,因此记录它看起来好像没有记录任何东西。然后,在以后的渲染中,您将看到数据。不确定,但有可能。