var bindif = [{
"ifname": "Ge0/2/1",
"ip": "20.1.1.1",
"mask": "255.255.255.0"
}, {
"ifname": "Ge0/2/5",
"ip6addr": "2000::254"
}, {
"ifname": "Ge0/2/5",
"ip": "40.1.1.1",
"mask": "255.255.255.0"
}];
var result = bindif.reduce(function (pre, curr) {
var exist = pre.find(function (dt) {
return dt.ifname === curr.ifname;
});
if(exist) {
if(curr.ip && exist.ip6addr){
exist.ip = curr.ip;
exist.mask = curr.mask;
}
if(curr.ip6addr && exist.ip){
exist.ip6addr = curr.ip6addr;
}
} else {
pre.push(curr);
}
return pre;
}, []);
console.log(result);