I have no clue how it passes without syntax errors.
JS is a dynamically typed language, you don't explicitly define the types of things.
Writing
Object object
is an error.
Instead, you use the
var
keyword for old JS code, and
let
or
const
for new code.
For example:
JavaScript:
let object = { ... };
object = [1, 2, 3]; // This is a dynamically typed language, types aren't static!
As to keys -
object[key]
or, if the key is a valid identifier,
object.key
.
In your case, all four keys are valid identifiers (as in, could be variable names), and so you can choose either way.
JavaScript:
object["something1"]
object.something1
Note that the key in the first notation is always converted to a string.
object[1]
for example, is the same as
object["1"]
.
If you ever need to map any type of key to any type of value, see
Map.
/Edit
Err...I just reread your post and saw this wasn't your question, but I'll keep the above text still it's still relevant.
If you want to get the names of the properties that an object holds, use the static
Object.keys
function.
JavaScript:
let keys = Object.keys(object);
for (let key of keys) {
console.log(key);
}