对象数组,如果key中的value相同,不要该项

对象数组,如果key中的value相同,不要该项
<script type=”text/javascript”>
  
let arr=[
{
gradeId: “498094709437239572”,
gradeName: “2018级”,
stageId: “2”,
stageName: “初中”,
},
{
gradeId: “498094709437239572”,
gradeName: “2018级”,
stageId: “2”,
stageName: “初中1”,
},
{
gradeId: “498094709437239572”,
gradeName: “2018级”,
stageId: “2”,
stageName: “初中2”,
},
{
gradeId: “498094709437239572”,
gradeName: “2018级”,
stageId: “2”,
stageName: “初中1”,
},
{
gradeId: “498094709437239572”,
gradeName: “2018级”,
stageId: “2”,
stageName: “初中3”,
},
]
// 先找出不同的阶段,对象数组,如果key中的value相同,不要该项
let newArr=[]
let lastUseArr=[];
for(let i=0;i<arr.length;i++){
if(newArr.indexOf(arr[i].stageName)==-1){
newArr.push(arr[i].stageName)
lastUseArr.push(arr[i])
}
}
console.log(lastUseArr)
  
</script>

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64711.shtml

张贴在3