JS defines a Java-like map for easy value

Source: Internet
Author: User

JS defines a Java-like map for easy value.

Baidu has a big God said, "JS object itself is a map structure", this is really a piece of code that makes people joyfully.

<script>//define a global map    varMap = {}; varKey0 = ' 0 '; varKey1 = ' 1 '; MAP[KEY0]= ' 0-Real message '; Map[key1]= ' 1-Virtual message '; //row Gets the value of this row, index gets the indexed value    functionTestjsmap (key) {//If you traverse the map         for(varPropinchmap) {            if(Map.hasownproperty (prop)) {Console.log (' key is ' + prop + ' and value is ' +Map[prop]); }        }        varValue =Map[key]; returnvalue; }</script>

Referenced from: https://zhidao.baidu.com/question/1111494250799257659.html

JS defines a Java-like map for easy value

Related Article

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.