0

Here's my functtion

var getLocaleDefault = function(settings){
    var defaultLocale = settings.defaultLocale;
    eval('var locale = settings.locale.'+defaultLocale);
    return locale;
}

settings is a JSON.parse()ed object of a JSON

{

    "classes": 8,
    "config": "classConfig",
    "locale": {
        "en": "localeEn"
    },
    "defaultLocale": "en"
}

As the code is: I am trying to get object.locale.en just because defaultLocale is en. Is there a better way other than eval to achieve what i am trying to do? Or is it the best/effective way of doing these kind of works?

1 Answer 1

1
var locale = settings.locale[defaultLocale];
return locale;

Even better,

var getLocaleDefault = function(settings){
    return settings.locale[settings.defaultLocale];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. (I am literally laughing on myself :) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.