Additional Object Methods - Let's Learn ECMAScript 2021 with Earl Duque
In this lesson, we're
going to be focusing on objects again and inside of objects,
specifically a bunch of new methods that make the objects functionality
even more robust. So on the screen,
I have created an object, an incident object
with an IDs status and priority property. And one of the new functionalities
that we have within objects
now is called getOwnPropertyDescriptors. And so if I go ahead and create
a new descriptors variable and I say object.getOwnPropertyDescriptors. and I give it an existing incident object. What it's doing
is it's creating a new object, but templated off of the incident object, but in a much more verbose way. So let me explain
and I'm going to explain that by doing a log statement
and I'm going to stringify that object so that we can take a closer look at it. And I'm going to add some extra parameters in here
to make it a little bit more pretty. I'm going to press run. So our original object had ID and a value, a status and a value
and a priority and a value. But instead
this new object has the same things, same properties, but each of them are now an object and in each of those objects, the property value as an actual property
and then the original value set as that values value, whether it's writable, enumerable,
and configurable. So a lot more verbose
and a lot more understanding of what you can actually do
with each of those objects. And if I want to access the value of id,
but in my new descriptors, object,
all I have to remember to do is say value. There it is Next, I want to show you the fromEntries
method that we have inside of objects. So if you see here I have a array
of arrays with strings in them, so this array has several arrays
inside of it. I can create a new object
and call it newincident. and I'm going to use the fromEntries
method for that original array. and let's
go ahead and print that new object. I'm going to stringify it
so that we can actually read it instead of seeing object object, and let's print it. So it took those arrays
and created an object out of those arrays according to how they were ordered
inside of the original array.
https://www.youtube.com/watch?v=emomSHePwxw