JS: Property Key
Property Key
Property String Key Example
/* string property keys */ const jj = { "a": 1, b: 2 }; const kk = Object.keys(jj); console.log(typeof kk[0] === "string"); console.log(typeof kk[1] === "string");
π WARNING: Implicitly Convention of Number to String
If a key is not symbol or string, it is converted to string implicitly.
// int keys are auto converted to string type console.log(typeof Object.keys({ 3: "b" })[0] === "string");
Get Variable Value as Key Name (Computed Property Key)
To evaluate a variable as property key, put it inside a square bracket, like this:
obj = {[expr]:value}
Property Symbol Key
JavaScript, Property
- JS: Property Overview
- JS: Property Key
- JS: Property Dot Notation vs Bracket Notation
- JS: Create Property
- JS: Delete Property
- JS: Get Set Property
- JS: Check Property Existence
- JS: Access Property
- JS: List Properties
- JS: for-in Loop
- JS: Enumerable Property
- JS: Property Attributes
- JS: Property Descriptor
- JS: Getter Setter Properties