2025年01月19日 建站教程
js从2个多维数组中根指定id取出不同的值重新生成数组!
代码如下:
var arr1 = [{ "name": "小骨", "sex": "女" }, { "name": "小米", "sex": "男" }]; var arr2 = [{ "name": "小米", "sex": "男" }, { "name": "小龙", "sex": "男" },{ "name": "小骨", "sex": "女" }]; var result = []; for (var i = 0; i < arr2.length; i++) { var obj = arr2[i]; var name = obj.name; var isExist = false; for (var j = 0; j < arr1.length; j++) { var aj = arr1[j]; var n = aj.name; if (n == name) { isExist = true; break; } } if (!isExist) { result.push(obj); } } console.log('输出结果:', result);
本文链接:http://so.lmcjl.com/news/21642/