zoukankan      html  css  js  c++  java
  • 合并数组

    方法一(Js):A.concat(B)

    示例一:  

    var a = ["a", "b", "c"];
    var b = ["b", "c", "d"];
    var c = a.concat(b);
    console.log("合并:",c);
    console.log("长:",c.length);
    var d = $.unique(c); //jquery中的方法
    console.log("去重:",d);
    console.log("长:",d.length);

    输出:

     示例二:

    var aObj = [
    { name : "小明",age : "21", sex : "男"},
    { name : "小红",age : "20", sex : "女"},
    { name : "张三",age : "24", sex : "男"},
    { name : "思思",age : "22", sex : "女"},
    ];
    var bObj = [
    { name : "韩雪",age : "21", sex : "女"},
    { name : "飘香",age : "20", sex : "男"},
    { name : "徐元",age : "24", sex : "男"},
    { name : "倾城",age : "23", sex : "女"},
    ];
    var cObj = aObj.concat(bObj);
    console.log("cObj",cObj);

    输出:

    方法二(jQuery):$.merge(A,B)

    示例一: 

    var a = ["a", "b", "c"];
    var b = ["b", "c", "d"];
    var c = $.merge(a,b);
    console.log("合并:",c);
    console.log("长:",c.length);
    var d = $.unique(c); //jquery中的方法
    console.log("去重:",d);
    console.log("长:",d.length);

    输出:

    示例二:

    var aObj = [
    { name : "小明",age : "21", sex : "男"},
    { name : "小红",age : "20", sex : "女"},
    { name : "张三",age : "24", sex : "男"},
    { name : "思思",age : "22", sex : "女"},
    ];
    var bObj = [
    { name : "韩雪",age : "21", sex : "女"},
    { name : "飘香",age : "20", sex : "男"},
    { name : "徐元",age : "24", sex : "男"},
    { name : "倾城",age : "23", sex : "女"},
    ];
    var cObj = $.merge(aObj,bObj)
    console.log("cObj",cObj);

    输出:

     

     



  • 相关阅读:
    js实现点击隐藏图片
    绝对定位给图片四角加上图片修饰
    雪碧图实现登陆页面
    弹性盒模型
    数组练习--求数组和,平均值,最大值,最小值
    h5与c3权威指南笔记--css3结构性伪类选择器root,not,empty,target
    h5与c3权威指南笔记--css3新属性选择器
    闲聊Java里的随机数
    Python之简单抓取豆瓣读书信息
    中本聪比特币论文
  • 原文地址:https://www.cnblogs.com/uakora/p/6906365.html
Copyright © 2011-2022 走看看