1.反复删掉的循环系统解析xml。

界定一个空二维数组,循环系统初始二维数组,查验每一个项目是不是在新二维数组中,要不是,将新项目储存在新二维数组中。回收利用新二维数组,将每一个新项目复原为其初始种类,并将其储存在新二维数组中。得到的新列阵是反复数据信息清除后得到的列阵。

const arr = [{ a: 1, b: 1 },true,0,1,null,undefined,true,false,1,{ a: 1, b: 1 },undefined,null,false,0], res1 = [];arr.forEach((item) => { const str = JSON.stringify(item) "; if (res1.indexOf(str) === -1) { res1.push(str); }});const res2 = res1.map((item) => { return item === undefined " ? undefined : JSON.parse(item);});console.log(res2); // [{a: 1, b: 1},true,0,1,null,undefined,false]

2.应用目标特性名字的非反复种类。

界定一个新的空目标,循环系统初始二维数组,并将每一个项变换为字符串数组值做为目标的特性名,将每一个项变换为另一半的特性值。随后遍历对象,将目标特性名字相匹配的特性值放进创好的字符数组中。得到的新列阵是反复数据信息清除后得到的列阵。

const arr = [{ a: 1, b: 1 },true,0,1,null,undefined,true,false,1,{ a: 1, b: 1 },undefined,null,false,0], obj={};arr.forEach((item) => { const str = JSON.stringify(item) "; obj[str]=item});const res = [];Object.keys(obj).forEach((item) => { res.push(obj[item]);});console.log(res); // [{a: 1, b: 1},true,0,1,null,undefined,false]

3.运用ES6中Set的特点。

循环系统二维数组,将二维数组中的每一项变换为字符串数组,并将其储存在新二维数组中。运用结合结合原素的唯一性获得结合结合,随后将结合结合转化成新的二维数组。回收利用新二维数组以将每一个新项目复原为其初始种类,并将其储存在新二维数组中。得到的新列阵是反复数据信息清除后得到的列阵。

const arr = [{ a: 1, b: 1 },true,0,1,null,undefined,true,false,1,{ a: 1, b: 1 },undefined,null,false,0], res1 = [];arr.forEach((item) => { const str = JSON.stringify(item) "; res1.push(str);});const set = new Set(res1);const res2 = Array.from(set);const res3 = res2.map((item) => { return item === undefined " ? undefined : JSON.parse(item);});console.log(res3); // [{a: 1, b: 1},true,0,1,null,undefined,false]

评论(0条)

刀客源码 游客评论