Is it possible to get this to work?
var DaysList = {1:"monday", 2:"tuesday", 3:"wednesday"}
alert(DaysList .1);
I want to prevent using a switch case statement in order to get the value (Eg Monday where I have the ID of 1)
This is not the real world problem, just an example.
Use square brackets to access DaysList object properties:
var DaysList = {1:"monday", 2:"tuesday", 3:"wednesday"};
alert(DaysList[1]); // Alerts "monday"
alert(DaysList[2]); // Alerts "tuesday"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.