Get the value of the first object property using Object.values() and array destructuring.

const obj = {
  myKeyA: 'my value A',
  myKeyB: 'my value B',
}

const [valueOfFirstObjectProperty] = Object.values(obj)

console.log('Value:', valueOfFirstObjectProperty) // my value A

See example online at https://codesandbox.io/s/value-of-the-first-object-property-b7dvj


Did you find it interesting? Follow me on Twitter.

Categories: snippet

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *