限定key,输出去重后的数组,期望数组如下;
作者:互联网
求:限定key,输出去重后的数组,期望数组如下;
已经知道数据集:
const data = [
{name:'A',age:17},
{name:'B',age:18},
{name:'C',age:19},
{name:'B',age:18},
{name:'C',age:19},
]
keys_list = ['A','C']
求:限定key,输出去重后的数组,期望数组如下;
result = [
{name:'A',age:17},
{name:'C',age:19}
]
function handleCookies(cookiesObj) {
var _cookeis = ''
let res = []
const keys_list = ['A','C']
for (let i in cookiesObj) {
const name = cookiesObj[i].name;
console.log(name,'name')
if (keys_list.includes(name) && (res.includes(name) === false)) {
const age = cookiesObj[i].age
_cookeis += cookiesObj[i].name + '=' + cookiesObj[i].age + ';';
}
res.push(name)
}
console.log('_cookies', _cookeis);
}
handleCookies(data)
标签:const,数组,cookiesObj,age,重后,key,cookeis,name 来源: https://www.cnblogs.com/ministep/p/15737610.html