I have following code snippet. I need to add this to a loop. What is the best way that I can follow.
A js object named Data is passed to the following JavaScript method and I need to check whether certain key are assigned the value "". Currently I'm using set of 'if' statement as below but I would like to acheive this using a loop.
privateMethods.generatePasswordDataPayload = function (Data) {
if (Data["passwordLength"] == "") {
Data["passwordLength"] = null;
}
if (Data["passwordComplexCharactors"] == "") {
Data["passwordComplexCharactors"] = null;
}
if (Data["passwordExpTime"] == "") {
Data["passwordExpTime"] = null;
}
if (Data["passwordHistory"] == "") {
Data["passwordHistory"] = null;
}
if (Data["passwordAttempts"] == "") {
Data["passwordAttempts"] = null;
}
}
Can I use any regex patterns and do something similar as below (pseudo code)
var i = 0;
while (Data.length >= i){
if ((Data["password(regex pattern check)") == ""){
(Data["password(regex pattern check)") == null;
}
i++;
}
Please note that I'm using JavaScript here.