How to make the JS variable and string concatenation, is a variable instead of a string

Source: Internet
Author: User

Today, there is a very interesting thing, because I need to use JS to achieve multi-language, I am in the JS file defined a different variable, try to use a variable concatenation string to make a defined variable name, the result stitching, the display is a string, not a variable, so cannot parse

zh_test = ' Hello ';    tw_test = ' Hello ';    En_test = ' Hello ';    Then JS try to use the previous language shorthand as a variable, splicing the string behind the    var lang = ' zh ';    var language = lang + ' _test ';  <pre name= "Code" class= "JavaScript" >alert (language); The result ' lang_test '      <pre name= "code" class= "JavaScript" >//then the result of the alert is lang_test, but this is obviously not what I want, What I want is to read the Chinese Simplified ' hello ' after stitching  , and I want it to be identified as a variable instead of a string, and finally with an eval () function to solve it;    var language = eval (lang + ' _test ');  alert (language); The result ' Hello '    is not a big article, just some small knowledge points encountered, share sharing

How to make the JS variable and string concatenation, is a variable instead of a string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.