I am a beginner in Javascript. I am creating a project using Javascript that has two JSON arrays:
var interfaces = [
{id:'123123-12-31-23',mac:'234',flowid:'1',status:'deployed'},
{id:'456456-12-31-23',mac:'45645',flowid:'2',status:'deployed'},
{id:'123123-12-31-234',mac:'45',flowid:'3',status:'deployed'},
{id:'456456-12-31-234',mac:'89',flowid:'4',status:'deployed'}
];
var reorderedInterfaces = [
{id:'456456-12-31-23',mac:'45645',flowid:'2',status:'deployed'},
{id:'456456-12-31-234',mac:'89',flowid:'4',status:'deployed'},
{id:'123123-12-31-234',mac:'45',flowid:'3',status:'deployed'},
{id:'123123-12-31-23',mac:'234',flowid:'1',status:'deployed'},
];
I need the following output:
var finalOutput = {
1:2,
2:4,
3:3,
4:1
}
Here is my code:
var obj = {}
for(i=0; i<interfaces.length; i++){
console.log()
for(j=0; j<reorderedInterfaces.length; j++){
obj[interfaces[i].flowid] = reorderedInterfaces[j].flowid
break;
}
}
console.log(obj)
This gives me wrong output