April 2018
Beginner to intermediate
426 pages
10h 19m
English
To implement the values method, we can also use a built-in method from the Object class named values as follows:
values() { return Object.values(this.items);}
If we want to write a code that can be executed in any browser, we can use the following code, which is equivalent to the previous code:
valuesLegacy() {
let values = [];
for(let key in this.items) { // {1}
if(this.items.hasOwnProperty(key)) { // {2}
values.push(key);
}
}
return values;
};
So, first, we will iterate through all the properties of the items object ({1}), add them to an array ({2} ...