How to filter an array of JavaScript objects?

Lets say I have the following object

var ob = [
  {
    "id": 1,
    "comment": "some comment",
    "hidden": 0,
  },
  {
    "id": 2,
    "comment": "some comment",
    "hidden": 1,
  },
  {
    "id": 3,
    "comment": "some comment",
    "hidden": 1,
  },
  {
    "id": 4,
    "comment": "some comment",
    "hidden": 0,
  }
]

How can I filter this to say for example return all where hidden = 1

Cheers

Answer

Use Array#filter:

let arr = [
  {
    "id": 1,
    "comment": "some comment",
    "hidden": 0,
  },
  {
    "id": 2,
    "comment": "some comment",
    "hidden": 1,
  },
  {
    "id": 3,
    "comment": "some comment",
    "hidden": 1,
  },
  {
    "id": 4,
    "comment": "some comment",
    "hidden": 0,
  }
];
let res = arr.filter(x => x.hidden === 1);
// or arr.filter(({hidden}) => hidden === 1);
console.log(res);