【发布时间】:2019-02-15 01:23:11
【问题描述】:
我有一个已转换为数组的对象 使用这个
convertToArray(data: any) {
let arr = [];
Object.keys(data).map(function(key){
arr.push(data[key]);
});
return arr;
}
这是结果
{0: {…}, 1: {…}, 2: {…}, hideTitle: false, template: "football-news", customProperties: {…}}
0: {NewsID: 90, AnotherAttribute: 5, …}
1: {NewsID: 90, AnotherAttribute: 5, …}
2: {NewsID: 90, AnotherAttribute: 5, …}
customProperties: {template: "list-view"}
hideTitle: false
template: "news"
__proto__: Object
到
(6) [{…}, {…}, {…}, false, "football-news", {…}]
0: {NewsID: 90, AnotherAttribute: 5, …}
1: {NewsID: 90, AnotherAttribute: 5, …}
2: {NewsID: 90, AnotherAttribute: 5, …}
3: false
4: "news"
5: {template: "list-view"}
length: 6
__proto__: Array(0)
我想删除任何没有 NewsID 键的项目(arr.pop 或过滤器)。
感谢您提前提供的任何帮助 :)
【问题讨论】:
-
将输入添加为文本请不要作为图像
-
你要我在这里复制200行JSON吗?我不介意,但jJSONon本身不是我的问题,我截取了截图帮助理解
-
您可以创建一个虚拟数据伙伴,无需发布您的完整 json。这将帮助人们快速准确地回答
标签: javascript arrays json object ecmascript-6