For example when you have an object
const obj = {
time,
difficulty,
distance,
}
The values that are inside of the object are saved as keys, correct? If I was to call Object.keys() on the object I would receive array of individual string elements?
CodePudding user response:
Using that notation, the property name
will be the key, and the property value
will be the value. This syntax was introductes in ES6.
It is the same as
const obj = {
'time': time,
'difficulty': difficulty,
'distance': distance
}
CodePudding user response:
When you call Object.keys()
it returns an array of the property names, not their values.
You can use an object like an associative array to make it act like a key/value pair.
someObject[“someKeyName”]