Вы можете использовать Object.keys
для итерации ключа в объекте, startsWith
для проверки текста macadress и использовать reduce
для вывода вашего требования как
var result = Object.keys(obj.facts_hash).reduce((acc, item)=>{
if(item.startsWith("macaddress")) console.log(obj.facts_hash[item]);
}, []);
или
var result = Object.keys(obj.facts_hash).reduce((acc, item) => {
if (item.startsWith("macaddress")) {
//console.log(obj.facts_hash[item]);
acc.push(obj.facts_hash[item]);
}
return acc;
}, []);
console.log(result);
var obj = {
"facts_hash": {
"lib": "/usr/share/fdi/facts:/opt/extension/facts",
"interfaces": "eno1,eno2,eno3,eno4,eno5,eno6,ens3f0,ens3f1,lo",
"ipaddress_eno1": "192.168.101.135",
"macaddress_eno1": "08:f1:ea:6d:03:3c",
"netmask_eno1": "255.255.255.0",
"mtu_eno1": "1500",
"macaddress_eno2": "08:f1:ea:6d:03:3d",
"mtu_eno2": "1500",
"macaddress_eno3": "08:f1:ea:6d:03:3e",
"mtu_eno3": "1500",
"macaddress_eno4": "08:f1:ea:6d:03:3f",
"mtu_eno4": "1500",
"macaddress_eno5": "b8:83:03:81:4b:20",
"mtu_eno5": "1500",
"macaddress_eno6": "b8:83:03:81:4b:21",
"mtu_eno6": "1500",
"macaddress_ens3f0": "b8:83:03:84:d5:1c",
"mtu_ens3f0": "1500",
"macaddress_ens3f1": "b8:83:03:84:d5:1d",
},
"name": "daisy-joni-selitto-quinto",
"id": 269
}
var result = Object.keys(obj.facts_hash).reduce((acc, item)=>{
if(item.startsWith("macaddress")) console.log(obj.facts_hash[item]);
}, []);
//console.log(result);