• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

New Object Methods Land in Chrome

ES2017, Javascript · March 3, 2016

Support for Object.values(), Object.entries() and Object.getOwnPropertyDescriptors() has landed in the Google Chrome dev channel. These newly added methods are currently candidate proposals and at stage 3 for the ES2017 specification. Many of us were using Lodash for some of the aforementioned missing features from browsers like Object.values. So these are welcome additions.

Keep in mind that these have not landed in the consumer release version of Google Chrome, maybe in a month or two we will see these released, perhaps even sooner. For the moment they are hidden behind a flag and only in the Canary version, enabled in options under “Experimental Javascript”. I did not realise these additions were so far along in the specification and hopefully provided there are no delays, we see them land in the finalised spec later next year.

If you are not aware of what any of these methods are for, here is a brief explainer for you.

Object.values
Returns an array of an objects enumerable property values. So if you had an object with the following values: var obj = {prop: 'me', prop2: 'far', prop3: 'so', prop4: 'la'} and ran that through Object.values(obj), you would get the following: ['me', 'far', 'so', 'la']

Object.entries
Returns an array of an objects enumerably keys and values in pairs [key, value]. Taking the previous object example: var obj = {prop: 'me', prop2: 'far', prop3: 'so', prop4: 'la'} and running that through Object.entries(obj) you would get the following: [ ['prop', 'me'], ['prop2', 'far'], ['prop3', 'so'], ['prop4', 'la'] ]. This is a game changer for many reasons, but it allows us to iterate over the properties of an object.

Object.getOwnPropertyDescriptors
This one is a mouthful to type, huh? This method returns an object that is comprised of each own non-inherited property of the supplied object, it adds a property to the returned object with a matching key and value which is the former properties descriptor.

The exciting thing about this addition is that it will allow us to copy properties into an object without abusing Object.assign and most exciting of all, we can use it to clone objects. You could clone an object using code like this: let cloned = Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj)); – this creates a new object, takes the prototype value of our supplied object and gets the keys/values using the getOwnPropertyDescriptors method.

Dwayne

Leave a Reply Cancel reply

0 Comments
Inline Feedbacks
View all comments

Primary Sidebar

Popular

  • Thoughts on the Flipper Zero
  • I Joined Truth Social Using a VPN and Editing Some HTML to Bypass the Phone Verification
  • How To Install Eufy Security Cameras Without Drilling or Using Screws
  • How To Get The Hash of A File In Node.js
  • Wild Natural Deodorant Review
  • The Most Common iPhone Passcodes (and how to guess them)
  • NBN Box Installed Inside of Garage, Where Do You Put The Modem?
  • How to Record With the Neural DSP Quad Cortex in Reaper (DI and USB Recording)
  • How To Paginate An Array In Javascript
  • Improving The Coopers Australian Pale Ale Extract Tin (and other tips)

Recent Comments

  • CJ on Microsoft Modern Wireless Headset Review
  • Dwayne on Microsoft Modern Wireless Headset Review
  • CJ on Microsoft Modern Wireless Headset Review
  • john on Microsoft Modern Wireless Headset Review
  • Dwayne on Why You Should Be Using globalThis Instead of Window In Your Javascript Code

Copyright © 2023 · Dwayne Charrington · Log in

wpDiscuz