[JQuery Learning Series three]3-jquery learning two-dictionary operation

Source: Internet
Author: User

Objective:
If you have read the first and second, I believe that you will have a preliminary understanding of jquery, for the jquery selector and array of operations are already familiar with, this article is a separate list of the operation of the dictionary in jquery related content.

1. Add a map to the array

var arr = []; var key = ' Jeremy '; var value = '!!!! ' arr.push ({' key ': Key, ' value ': value,}); document.write ("key:" + arr[0][' key ') + "<br/>value:" + arr[0][' value '); output: key:jeremyvalue:!!!!

2. Array traversal output

var arr = []; Arr.push ("Jeremy"); Arr.push ("Jimmy"); for (var i in arr) document.write (i + ":" + arr[i] + "</br>"); Output: 0:jeremy1:jimmy

3. Similar dictionary (map) traversal

var dict = []; or dict = new Array () dict["Jeremy"] = 20; dict["Jimmy"] = 30; for (var key in Dict) document.write (key + ":" + Dict[key] + "</br>"); Output Result: jeremy:20jimmy:30


4. Assigning values when a dictionary is declared

var dict = {"Jeremy": +, "Jimmy": 30}; for (var key in Dict) document.write (key + ":" + Dict[key] + "</br>"); Output Result: jeremy:20jimmy:30

var dict = {"Jeremy": ["Chinese", "Math"], "Jimmy": ["Art", "中文版"]}; var name = "Jeremy"; for (Var courseindex in Dict[name]) document.write (Dict[name][courseindex] + "</br>"); Output Result: Chinesemath


5. The value in the dictionary is an array, which is a dictionary.

var dict = []; var courselistofjeremy = [{"Chinese": 3}, {"Math": 5}]; dict[' Jeremy '] = Courselistofjeremy; var courselistofjimmy = [{"Art": 3}, {"中文版": 5}]; dict[' Jimmy ' = courselistofjimmy; document.write ("Jimmy's Course number of Chinese:" + dict[' Jeremy '][0][' Chinese ']); output: Jimmy's Course number of Chinese : 3


Small example: Using JS to achieve three-level linkage between counties and cities

Effects such as:



English tips:

I ache all over.
I'm aching all over.
I ' m flattered.
That's a compliment.
I ' M mad at myself.
I was angry with myself.
I ' m not myself today.
I am uneasy today.
I ' m very/really/terribly/awfully/extremely sorry.
I'm very sorry.
I ' m working on it.
I'm trying.
It can ' t be helped.
Powerless.
I can ' t seem toget to sleep.
I can't seem to sleep.
I don ' t feel.
I feel unfit for the job.
I have a runny nose.
I have a runny nose.
I have a sweet tooth.
I like to eat sweets.

[JQuery Learning Series three]3-jquery learning two-dictionary operation

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.