ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1.# 把数组中每个元素的某个字段取出 ``` 方法:map() let cities = [   {city:"北京",bOn:false},   {city:"上海",bOn:false},   {city:"重庆",bOn:false},   {city:"广州",bOn:false},   {city:"西安",bOn:false} ];  let city = cities.map((item) =>{    return item.city  }); ``` 2.# 根据id取出数组中的对象 ``` var arr=[ {id: 1,name: 'a'}, {id: 2,name: 'b'}, ] var obj=arr.find(function (x) { return x.id === 1 }) ``` 3.# 去除对象中的空键值对 ``` var data={a:1,b:2,c:3,4:''} for ( var key in data ){ if ( data[key] === '' ){ delete data[key] } } ```