Objective
I want to compare each element of two arrays, when an element does not match in both of them, it gets pushed to another array.
Both array are of indefinite size.
Code So Far
Example:
//namelist will always have the values present, userlist will check if it has the elements in namelist, otherwise send to another array.
namelist = ['user1','user2','user3','user4','user5']
userlist = ['user4','user1','user3'] //'user2' and 'user5' are not present
//Does not work
let arr1 = [];
let arr2 = [];
for(let i = 0; i < namelist.length && userlist.length; i++){
if(namelist[i] == userlist[i]){
arr1 = userlist[i]
} else {
arr2 = userlist[i]
}
}
console.log(arr2);
["a", "b", "a"]and["a", "a", "a"]? What's the expected output for the given arrays?namelistitems not found inuserlistarray?