2021年3月20日星期六

Is there a Javascript data structure that can use a property as an enum index?

    var Index = {          X_OFFSET: 1,          Y_OFFSET: 2,          Z_OFFSET: 3,      };        var options = [          {name: "X Offset", min:0, max:100, value:0},          {name: "Y Offset", min:0, max:100, value:0},          {name: "Z Offset", min:0, max:100, value:0}      ]            var currentYOffset = options[Index.Y_OFFSET];  

[options] is structured so it can be easily saved as an XML file. But to get the value of an option without an index, I'd need to loop through the entire array each time, which just feels inefficient. A simple enum that is identical to the 'name' property would suffice.

EnumMap sounds like it would be appropriate, but doesnt help with XML element name which needs to be a string.

Are there any other data structures appropriate for this?

https://stackoverflow.com/questions/66728210/is-there-a-javascript-data-structure-that-can-use-a-property-as-an-enum-index March 21, 2021 at 10:07AM

没有评论:

发表评论