如何跳过对象数组中的零值?

时间:2018-07-30 02:40:20

标签: javascript javascript-objects

我正在尝试处理对象数组。在这里,我想忽略具有“ 0”值的对象,并通过遍历“ storyIds”以及任何想法来打印大于零的值。

var dataArr = [
 {number: 1, workId: [0], storyIds: [0]},
 {number: 2, workId: [0], storyIds: [0]},
 {number: 3, workId: [1], storyIds: [10]},
 {number: 4, workId: [2], storyIds: [10]},
 {number: 5, workId: [3], storyIds: [20]}
];

预期产量

3, 4, 5 //Output

1 个答案:

答案 0 :(得分:0)

var dataArr = [
 {number: 1, workId: [0], storyIds: [0]},
 {number: 2, workId: [0], storyIds: [0]},
 {number: 3, workId: [1], storyIds: [10]},
 {number: 4, workId: [2], storyIds: [10]},
 {number: 5, workId: [3], storyIds: [20]}
];

console.log(dataArr.filter((v) => !!v.storyIds[0]))