如何使用Javascript区分相同的对象数据值? [ES15 / ES16]
给定数据值
google.maps.event.addListener( marker, 'dragend', function ( event ) {
document.getElementById( "input_latitude" ).value = event.latLng.lat();
document.getElementById( "input_longitude" ).value = event.latLng.lng();
} );
之后它将会分开
[{Zone: "2"},
{Zone: "4"},
{Zone: "4"},
{Zone: "6"},
{Zone: "1"},
{Zone: "2"},
{Zone: "3"},
{Zone: "3"},
{Zone: "4"},
{Zone: "4"}]
答案 0 :(得分:1)
一种可能的方法:
var arr = [{Zone: "2"}, {Zone: "4"}, {Zone: "4"}, {Zone: "6"}, {Zone: "1"}, {Zone: "2"}, {Zone: "3"}, {Zone: "3"}, {Zone: "4"}, {Zone: "4"}]
var resp = [...new Set(arr.map(({ Zone }) => Zone))].sort().map(x => ({Zone: x}));
console.log(resp);

.as-console-wrapper { max-height: 100% !important; top: 0; }

对于这种新方法,您可以map
上面的resp
使用原始数组中filter
的{{1}}作为:
Zones

var arr = [{Zone: "2" , Assign: "1"}, {Zone: "4", Assign: "2"}, {Zone: "4", Assign: "3"}, {Zone: "6", Assign: "4"}, {Zone: "1", Assign: "5"}, {Zone: "2", Assign: "6"}, {Zone: "3", Assign: "7"}, {Zone: "3", Assign: "8"}, {Zone: "4", Assign: "9"}, {Zone: "4", Assign: "10"}]
var resp = [...new Set(arr.map(({ Zone }) => Zone))].sort().map(x => ({Zone: x}));
var newresp = resp.map(({ Zone }) => {
var assigns = arr.filter(x => x.Zone == Zone).map(x => x.Assign);
return {
Zone: Zone,
Assign: assigns
}
})
console.log(newresp)

答案 1 :(得分:0)
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-jobclient</artifactId>
<version>2.6.0</version>
</dependency>