【发布时间】:2018-12-20 23:41:44
【问题描述】:
我希望能够获取一个字符串数组:
这是我正在使用的模拟数据。
const archives = {
"data": [{
"id": 1,
"type": "archive",
"attributes": {
"name": "Employee Engagement Summary",
"description": "Report description goes here",
"creation_date": "March 21, 2018",
"date_range": "03/01/2018-05/15/2018",
"data_sets": "Facility A, Nursing Department"
}
},
{
"id": 1,
"type": "archive",
"attributes": {
"name": "Sample Survey 1",
"description": "Report description goes here",
"creation_date": "March 21, 2017",
"date_range": "03/01/2017-05/15/2017",
"data_sets": "Facility A, Nursing Department"
}
},
{
"id": 1,
"type": "archive",
"attributes": {
"name": "Sample Survey 2",
"description": "Report description goes here",
"creation_date": "March 21, 2016",
"date_range": "03/01/2016-05/15/2016",
"data_sets": "Facility A, Nursing Department"
}
},
{
"id": 1,
"type": "archive",
"attributes": {
"name": "Sample Survey 3",
"description": "Report description goes here",
"creation_date": "March 21, 2015",
"date_range": "03/01/2015-05/15/2015",
"data_sets": "Facility A, Nursing Department"
}
}
]
};
export default archives;
上面的代码拥有我正在使用的真实模拟数据。
然后从中提取年份。因为我希望能够遍历这些年并将它们放在一个列表中
<ul>
<li>2018</li>
<li>2017</li>
<li>2016</li>
<li>2015</li>
<li>2014</li>
<li>2013</li>
<li>2012</li>
</ul>
【问题讨论】:
-
请发布您的代码。
-
第 3 行的附加 f 是错字吗?
-
有时候会很无聊……例如就像这里一样,所有答案都被否决了,没有真正的解释。这与 SO 的否决权有何关系,他说:“应为极端情况保留否决权。它不能代替沟通和编辑。与其否决票:如果有问题,请留下一个评论或编辑帖子以更正它。”
-
@Bucket 我发布了我正在使用的实际模拟数据。
标签: javascript html json regex