我如何从Object获取键的值?

时间:2019-12-04 09:13:34

标签: javascript jquery json

我想从下面的对象中获取工作日的值。怎么能得到这个? 我正在获得未定义的值。我也使用JSON.parse,但仍然出现另一个错误。

var timecardDayDetails = [{
    "projectId": 'projectName',
    "activityId": 'projectActivity',
    "location": 'projectLocation',
    "taskDetails": 'projectComments',
    "workingDay": 'Monday',
    "workingDate": "2019-11-04",
    "workingHours": 'workingHours',
    "startTime": 'tsTimeStart',
    "endTime": 'tsTimeEnd',
    "status": "draft"
  },
  {
    "projectId": 'projectName',
    "activityId": 'projectActivity',
    "location": 'projectLocation',
    "taskDetails": 'projectComments',
    "workingDay": 'Monday',
    "workingDate": "2019-11-04",
    "workingHours": 'workingHours',
    "startTime": 'tsTimeStart',
    "endTime": 'tsTimeEnd',
    "status": "draft"
  }
]

var parsedData = JSON.stringify(timecardDayDetails);

alert(parsedData['workingDay']);

1 个答案:

答案 0 :(得分:1)

这是数组,因此您需要定义索引以获取值

modified然后像t timecardDayDetails[0]

imecardDayDetails[0]['workingDay']