What is the recommended way to filter Objects with Unique property in the array in JS?

后端 未结 4 765
醉梦人生
醉梦人生 2021-01-29 06:53

How to filter objects in array based on unique property here i have an array where KEY is the key value in the objects. How to filter the objects where key value is unique. Key

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-29 07:19

    var uniqueArray = []
    for (var i = 0; i < array.length; i++) {
        var uniquevalue = array[i];
        unique[array.KEY] = uniquevalue;
    }
    for (var name in unique) {
        var uniqueObject = unique[name];
        uniqueArray.push(uniqueObject);
    }
    

提交回复
热议问题