I want to generate a string based on user input, it should looks like: 1234-2016-abc12-3232, i have 7 options like roll_number, user_id, user_name, year, department, class, subject_code. The sequence of this options is user define. Ex: a user can say i want user_name first then subject_code then roll_number and so on, user can also choose how many character he wants from a particular option means he can say last 2 character from roll_number, first 3 character from user_name and so on.
===What i tried===
First i captured all the information in 4 array:
The first array is:
var selectedOptions = ['user_name', 'roll_number', 'subject_code', 'class'];
so i got the list of options which i have to take for string creation.
The second array is:
var sequence = [
{ key:'user_name', value:2 },
{ key:'subject_code', value:3 },
{ key:'class', value:1 },
{ key:'roll_number', value:4 },
];
this array gives the sequence of option.
Third array is:
var alignment = [
{ key:'user_name', value:'left' },
{ key:'subject_code', value:'left' },
{ key:'class', value:'right' },
{ key:'roll_number', value:'left' },
];
It gives the knowledge of alignment for example if roll_number is 123456 and user selected the length as 3 from right then 456 should be taken, so this is the left and right information.
The fourth array is:
var lengthOfOptions = [
{ key:'user_name', value:3 },
{ key:'subject_code', value:4 },
{ key:'class', value:2 },
{ key:'roll_number', value:5 },
];
===Then===
The values of this options:
var user_name = "1234abcd";
var subject_code = "567890";
var class = "2016";
var roll_number = "123";
Now using for loop i got the name of options, then i tried to get the sequence but i am not able to get the sequence of a particular option because i am inside for loop and i am not sure i should get sequence first or option name first if you have any simple approach or a guideline for me please help, my point of view is i need to run loop inside loop but i don't know how? Thanks.
==EDIT==
my code for loop is
sequence.sort(function(a, b) {
return parseFloat(a.value) - parseFloat(b.value);
});
for (var i = 0; i <= sequence.length - 1; i++){
console.log("The key is :", sequence[i]['key']);
console.log("The value is :", sequence[i]['value']);
}
after this what to do i am not able to understand.
for loop, please?