数组去重

2020-07-23  本文已影响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])
}
上一篇下一篇

猜你喜欢

热点阅读