Objects are pretty handy data structures that consist of a key and value pairs. What they can contain can differ however, a key can be a symbol or a string while the value can be any data type.
Up above we have an object called animals. The keys are strings which serves as the type of animal. Where as the value is an integer which represents the number of specified animal. There are 3 object methods that can be used to shift through the given data.
This method returns an array of a given object’s enumerable property pairs.
With the following method, the object gets converted to an array so now it can be more easily manipulated to get specified information from the given object. For an example, if we wanted to find which animal had the highest number, we can use a sort method.
This will order the array in descending order. b — a will sort the array by comparing the values.
Now we have a sorted array of arrays and we can easily get the pair with the highest key value.
This method will return an array a given object’s keys.
This method will return an array a given object’s values.
This method is useful where you only care for the value portion of the object. An example being finding the highest, lowest or most frequent values.