Skip to content

Instantly share code, notes, and snippets.

@discoNeko
Last active January 17, 2020 20:03
Show Gist options
  • Save discoNeko/8d3617b70d2f8f19a3cb2d652ecafc5c to your computer and use it in GitHub Desktop.
Save discoNeko/8d3617b70d2f8f19a3cb2d652ecafc5c to your computer and use it in GitHub Desktop.
const id = "id1"
const results = { "aaa": { id: "id1", name: "111" }, "bbb": { id: "id1", name: "222" }, "ccc": { id: "id2", name: "333" }}
const array = Object.values(results).filter(result => result.id == id)
console.log(array)

> Array [Object { id: "id1", name: "111" }, Object { id: "id1", name: "222" }]
const id = "id1"
// const results = { "aaa": { id: "id1", name: "111" }, "bbb": { id: "id1", name: "222" }, "ccc": { id: "id2", name: "333" }}
const results = {}
const array = Object.values(results).filter(result => result.id == id)

> Array []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment