diff --git a/src/dns/namecheap.js b/src/dns/namecheap.js index c97fbb389..1e79c6c5d 100644 --- a/src/dns/namecheap.js +++ b/src/dns/namecheap.js @@ -249,25 +249,15 @@ function del(domainObject, subdomain, type, values, callback) { if (error) return callback(error); if (result.length === 0) return callback(); + const originalLength = result.length; - let removed = false; - - for (var i = 0; i < values.length; i++) { + for (let i = 0; i < values.length; i++) { let curValue = values[i]; - for (var j = 0; j < result.length; j++) { - let curHost = result[i]; - - if (curHost.Type === type && curHost.Name === subdomain && curHost.Address === curValue) { - removed = true; - - result.splice(i, 1); // Remove element from result array - } - } + result = result.filter(curHost => curHost.Type !== type || curHost.Name !== subdomain || curHost.Address !== curValue); } - // Only set hosts if we actually removed a host - if (removed) return setZone(dnsConfig, zoneName, result, callback); + if (result.length !== originalLength) return setZone(dnsConfig, zoneName, result, callback); callback(); });