Hope title is not too confusing but further explanation below.
var listName = ["Alexandros","Halvar","Herman","Luciano","Natana","Nihal","Priscilla","Tanja","Trish","Trish"]
var listID = ["10","6","4","8","1","7","2","3","5","9"]
var newList = ["Luciano","","Priscilla","Herman","Trish","Trish","Natana","Tanja","Nihal","Alexandros"]
I'm trying to find the index of each newList element in listName and then use the result to match the index in listID.
Afterwards create new array with the results like such:
var result = ["8","","2","4","5,9","5,9","1","3","7","10"]
With some help from this thread, this is as far i have gotten:
for (var i = 0; i < listName.length; i++) {
function getAllIndexes(arr, val) {
var indexes = [], i = -1;
while ((i = arr.indexOf(val, i+1)) != -1){
indexes.push(i);
}
return indexes;
}
var indexes = getAllIndexes(listName, newList[i]);
var result = []
result.push(String(listID[indexes]));
alert(result);
}
Result is good but returns undefined with elements that has two or more values (5,9).
Any help appreciated.