美文网首页
数组去重

数组去重

作者: 考拉程序媛 | 来源:发表于2020-07-23 15:34 被阅读0次
    
    
    let  channelTabList = [
         {1: '推荐'},
         {2: '最新'},
         {3: '快赚'}, 
         {4: '高额'}
    {1: "推荐", 2: "最新", 3: "快赚", 4: "高额"}
    let lists = channelTabList.reduce((acc,value)=>{
        return {...acc,...value}
    })
    ----------------------------------
    data:[
      {
        'Id': '1',
        'Phone': '123456',
        'Name': '张三',
      },
      {
        'Id': '2',
        'Phone': '78945',
        'Name': '李四',
      },
      {
        'Id': '3',
        'Phone': '123789',
        'Name': '王五',
      }
    ]
    
    //data json的名称,n是自定义取的
    let result = data.map(data => n.name).join();//'张三,李四,王五'
    
    let results = data.map(data => n.name);//['张三','李四','王五']
    ----------------------------------------------------------
    var obj=[{
        name:"yhh",
    },{
        sex:"女",
    },{
        work:"IT"
    }];
    console.log(Object.keys(obj[0])[0]);
    console.log(Object.values(obj[0])[0])
    for(var i  in  obj){
    console.log(Object.keys(obj[i])[0]);
    console.log(Object.values(obj[i])[0])
    }
    

    相关文章

      网友评论

          本文标题:数组去重

          本文链接:https://www.haomeiwen.com/subject/kfhftktx.html