key
must be a string
(or symbol), and the value can be any type, such as a number, string, function, or even another object.Object.keys(obj)
: Returns an array of the object's keys , in this case ["name", "age", "gender"].
Object.values(obj)
: Returns an array of the object's values, in this case ["Fabio", 28, "M"].
Object.entries(obj)
: Returns an array of key-value pairs, where each entry is an array containing a key and its associated value, in this case [["name", "Fabio"], ["age", 28], ["gender", "M"]]
.for...of
loop can be very useful to iterate over each element in the numbers array:for...of
loopObject.entries()
.