When I try to push the temp object of type update it creates duplicates instead of adding a new object to updatedjson. Basically I am reading list of ip address from a file and create new json objects of type sample and adding it to updatedjson array.
sample =[
{
"destination": "string",
"destinationType": "string",
"isStateless": true,
"protocol": 6,
"tcpOptions": {
"destinationPortRange": {
"max": 0,
"min": 0
}
}
}
];
var updatedjson = [];
var tempjson = sample[0];
tempjson.isStateless = false;
tempjson.protocol = 6;
tempjson.tcpOptions.destinationPortRange.min = 443;
tempjson.tcpOptions.destinationPortRange.max = 443;
tempjson.destinationType = "CIDR_BLOCK";
for (var i = 0; i < inputArray.length; i++) {
for (var j = 0; j < inputArray[i].cidrs.length; j++) {
var tempjson = sample[0];
tempjson.isStateless = false;
tempjson.protocol = 6;
tempjson.tcpOptions.destinationPortRange.min = 443;
tempjson.tcpOptions.destinationPortRange.max = 443;
tempjson.destinationType = "CIDR_BLOCK";
tempjson.destination = inputArray[i].cidrs[j];
addToUpdate(tempjson);
}
}
function addToUpdate(temp) {
updatedjson.push(temp);
}
Even if the tempjson.destination is different it pushes same object like for ip address 166.35.25.12/24 and 36.34.25.12/24 updatedjson is like this.
[
{
destination: '166.35.25.12/24',
destinationType: 'CIDR_BLOCK',
isStateless: false,
protocol: 6,
tcpOptions: { destinationPortRange: [Object] }
},
{
destination: '166.35.25.12/24',
destinationType: 'CIDR_BLOCK',
isStateless: false,
protocol: 6,
tcpOptions: { destinationPortRange: [Object] }
}
]