zoukankan      html  css  js  c++  java
  • JQuery学习二-字典操作

    1. 数组中添加map

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

    2. 数组遍历输出

    var arr = []; 
    arr.push("Jeremy"); 
    arr.push("Jimmy"); 
    for(var i in arr) 
    document.write(i + ": " + arr[i] + "</br>");
    
    输出结果:
    0: Jeremy
    1: Jimmy

    3. 类似字典(map)遍历

    var dict = []; //or dict = new Array() 
    dict["Jeremy"] = 20; 
    dict["Jimmy"] = 30; 
    for(var key in dict) 
    document.write(key + ": " + dict[key] + "</br>"); 
    
    输出结果:
    Jeremy: 20
    Jimmy: 30

    4. 字典声明时赋值

    var dict = { 
    "Jeremy" : 20, 
    "Jimmy" : 30 
    }; 
    for(var key in dict) 
    document.write(key + ": " + dict[key] + "</br>"); 
    
    输出结果:
    Jeremy: 20
    Jimmy: 30

    demo2

    var dict = { 
    "Jeremy" : ["Chinese", "Math"] , 
    "Jimmy" : ["Art", "English"] 
    }; 
    var name = "Jeremy"; 
    for(var courseIndex in dict[name]) 
    document.write(dict[name][courseIndex] + "</br>"); 
    
    输出结果:
    Chinese
    Math

    5. 字典里value为数组, 数组内为字典

    var dict = []; 
    var courseListOfJeremy = [ 
    {"Chinese" : 3}, 
    {"Math": 5} 
    ]; 
    dict['Jeremy'] = courseListOfJeremy; 
    var courseListOfJimmy = [ 
    {"Art": 3}, 
    {"English": 5} 
    ]; 
    dict['Jimmy'] = courseListOfJimmy; 
    
    document.write("Jimmy's Course Number Of Chinese: " + dict['Jeremy'][0]['Chinese']);
    
    输出结果:
    Jimmy's Course Number Of Chinese: 3
  • 相关阅读:
    FastDFS
    MYSQL日常操作
    SVN安装
    mysql主主配置
    MySQL优化
    nginx反向代理tomacat+keepalived实现动静分离、负载均衡、高可用
    nginx故障及处理
    nginx配置检测及安全配置
    nginx基本优化
    大金空调适配器
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10732835.html
Copyright © 2011-2022 走看看