json 的操作

json

let data = [  
  {"Networking": "apple", "count_value": "10"},  
    {"Networking": "orange", "count_value": "20"},  
    {"Networking": "banner", "count_value": "30"},  
    {"Networking": "watermelon", "count_value": "10"},  
    {"Networking": "pear", "count_value": "30"},  
    {"Networking": "grape", "count_value": "20"},  
    {"Networking": "cherry", "count_value": "50"},  
    {"Networking": "strawbery", "count_value": "60"},  
    {"Networking": "apple", "count_value": "70"},  
    {"Networking": "orange", "count_value": "80"},  
    {"Networking": "banner", "count_value": "90"},  
    {"Networking": "watermelon", "count_value": "40"}  
];
// 合并json中同名key值
    let obj = {};
    for(let i in data){
        if(obj[data[i].Networking]){
            obj[data[i].Networking].value = Number(obj[data[i].Networking].value) + Number(data[i].count_value);
        }else{
            obj[data[i].Networking] = {
                value: Number(data[i].count_value)
            }
        }
    }

//合并两个数组

    let str1=[{name:"11",age:11}];
    let str2=[{name:"22",age:22}];
    
    //1.方法一
    //let str3 = [];
    //for (let i = 0; i < str1.length; i++) {
    //  str3.push(str1[i]);
    //}
    // 
    //for (let i = 0; i < str2.length; i++) {
    //  str3.push(str2[i]);
    //}
    
    //2.方法二
    let str3 = str1.concat(str2);
//获取地址参数
    
    let searchUrl = 'http://10.10.0.200:8081/list?search=%E4%BD%A0%E5%A5%BD'; //window.location.href;
    let searchData = searchUrl.split("=");        //截取 url中的“=”,获得“=”后面的参数
    
    let  searchText = decodeURI(searchData[1]);   //decodeURI解码