I am trying to access values of a map via enum and also make a translation ready app for all the strings in it. Both concerns overlap and I have to decide between using enums or just object in JSON format.
So what exactly is the difference and useage between an enum and an object?
For example:
- I can use enums to access arrays as well as inserting labels and other stuff like
const enum FieldNames {
FirstField: "Field One",
SecondField: "Field Two"
};
someFieldArray[FieldNames.FirstField].label = FieldNames.FirstField;
someFieldArray[FieldNames.SecondField].label = FieldNames.SecondField;
- Or I can achieve the same behaviour via object
const FieldNames = {
FirstField: "Field One",
SecondField: "Field Two"
};
someFieldArray[FieldNames.FirstField].label = FieldNames.FirstField;
someFieldArray[FieldNames.SecondField].label = FieldNames.SecondField;
I really do not get the benefit choosing enums over simple objects. In my opinion an object has much more benefits without any downsides.