-6

I'm trying to handle an array of object. Where, I wanna ignore the object which has the value of '0' and print the values which is greater than zero by looping through 'storyIds', any ideas.

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]}
];

Expected Output

3, 4, 5 //Output
Pradeep
  • 11
  • 6
  • 2
    you want to *filter* out the elements in the array where something has a particular value ... array has a *`filter`* method that can be used for just such an occasion - a good source of documentation for such things is on MDN - https://developer.mozilla.org/bm/docs/Web/JavaScript – Jaromanda X Jul 30 '18 at 02:42

1 Answers1

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]))
Akrion
  • 18,117
  • 1
  • 34
  • 54