I have encountered a situation in my code where I have three java script variables in which two are arrays and one is a single string variable. The following are their structure:
var selectedUser = $('#Employees_SelectedValue').val(); //It has one one value "12121"
var selectedCountries = $('#Countries_SelectedValue').val(); //It has multiple values ["IND", "USA"]
var selectedSourceSystems = $('#SourceSystems_SelectedValue').val(); //It has multiple values ["SQL", "ORACLE", "MySQL"]
What I have to do is to add these values in a class on the basis of selectedUser such as User is same for all the values but the remaining two are different as:
var userSettings = { userName: selectedUser, userCountry: selectedCountries, userSourceSystem: selectedSourceSystems };
The situation is to add the values from this class into an array in such a way that every userCountry and userSourceSystem will come as a single entity such as:
{ userName: "12121", userCountry: "IND", userSourceSystem: "SQL" },
{ userName: "12121", userCountry: "USA", userSourceSystem: "ORACLE" },
{ userName: "12121", userCountry: "", userSourceSystem: "MySQL" }
I'm trying the approach of nested-for loop to handle this scenario like:
for (var i = 0; i < selectedCountries; i++)
{
for (var j = 0; j < selectedSourceSystems; j++)
{
userSettings.userName = selectedUser;
//Add i and j values
}
}
Please suggest an effective approach other than this.
{"12121", "IND", "SQL"}. error would be "Unexpected token ,"