3 ms·
Object property names are always strings, even though you can set them via number literals (as the person you replied to said): const object = {} objec
by matt_kantor 4y ago
Object property names are always strings, even though you can set them via number literals (as the person you replied to said):
const object = {}
object[1] = 3
console.log(object["1"]) // 3
for (const key in object) {
console.log(typeof key) // "string"
}
This is different from keys of the Map data structure, which are actually able to be any type of value (even silly stuff like other Maps).
- chrisseaton 4y agoI don't know - I think that proves what I said - map keys can be floats.
- matt_kantor 4y agoFor sure, I never disagreed with that (I even said "JavaScript maps absolutely can use numbers (or any type) as keys" in my other comment). But object property names cannot be floats (which is what your example was, despite them being properties of a Map object).