提问者:小点点

如何从对象中获取值[重复]


我有一个像这样的对象,我不知道如何从中获得单个值。 这就是它在控制台中的样子。

[
  {
    "startDate": "2020-07-14T14:29:53.525Z",
    "endDate": 1594823393525,
    "summary": "Visit of the Louvre",
    "status": "pending"
  }
]

我想从这个对象中获取状态的值。 我试过这样做,但它返回的是未定义的值。

str.status

任何有关这方面的建议都将是有益的。


共2个答案

匿名用户

首先访问变量中的对象,然后访问属性

null

object=[
  {
    "startDate": "2020-07-14T14:29:53.525Z",
    "endDate": 1594823393525,
    "summary": "Visit of the Louvre",
    "status": "pending"
  }
]

console.log(object[0].status)

匿名用户

您需要得到第0个索引。因此您得到如下的str[0]对象

要访问name属性,请执行以下操作。

字符串[0].状态

null

let str = [
  {
    "startDate": "2020-07-14T14:29:53.525Z",
    "endDate": 1594823393525,
    "summary": "Visit of the Louvre",
    "status": "pending"
  }
];

//then you can access like this
console.log(str[0].status);