var array=[ {id:1,name:'小明',sex:'男'}, {id:2,name:'小剛',sex:'男'}, {id:3,name:'小紅',sex:'女'}, {id:4,name:'小花',sex:'女'}, {id:5,name:'小甜甜',sex:'女'}, ] var obj={},newArr=[]; array.forEach(function(item,suffix){ //根據對象的屬性是唯一的,將值作為對象的屬性名 if(!obj[item.sex]){ var arr=[]; arr.push(item); newArr.push(arr); obj[item.sex]=item; }else{ newArr.forEach(function(value,index){ //如果已經存在 就循環新組的值將值插入屬性相同的數組里 為了防止重復添加 只要和第一個比較就可以了 if(value[0].sex==item.sex){ value.push(item) } }) } }) console.log(obj); console.log(newArr)