Skip to content

Instantly share code, notes, and snippets.

@albertywu
Last active April 29, 2021 17:27
Show Gist options
  • Select an option

  • Save albertywu/eaff781246a08ecbb7d3329f29085360 to your computer and use it in GitHub Desktop.

Select an option

Save albertywu/eaff781246a08ecbb7d3329f29085360 to your computer and use it in GitHub Desktop.
const o = { foo: 1, bar: 2 }
const a = [1, 2, 3]
// iterate over keys in object
for (prop of Object.keys(o)) {
console.log(prop)
}
// iterate over values in object
for (value of Object.values(o)) {
console.log(value)
}
// iterate over values in array
for (value of a) {
console.log(a)
}
// check if key is in object
console.log('foo' in o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment