let's see ... let's analyze your algorithm ...
The second for has the idea .. but it is not complete .. If you record the value in the data array without repetitions the first time it is not repeated, then you will record all the values of the second array. forever.
That is, you compare the 1 with the 3 .. obviously they are not the same .. then you record the 3. the question would be because?
to start? you should go through the array in reverse order, that is, look for the ones you want to know if they are or not, in the other .. something like this ...
for(var j=0;j<datos2.length;j++){
for(var k=0;k<datos1.length;k++){
if(datos1[j]!=datos2[k]){
datosNoRepetidos[j]=datos2[j];
}
}
}
Now, this obviously still does not solve your problem .. because it is missing .. something that says it is not in any place in the second array ...
For that ... let's add a flag ...
for(var j=0;j<datos2.length;j++){
var esta = false
for(var k=0;k<datos1.length;k++){
if(datos2[j]!=datos1[k]){
datosNoRepetidos[j]=datos2[j];
}
}
}
Let's suppose it is not .. this way .. if it is not .. it will never be true .. to make it true .. we do the following ...
So, let's add an if, that tells us if we add it or not
for(var j=0;j<datos2.length;j++){
var esta = false
for(var k=0;k<datos1.length;k++){
if(datos2[j]!=datos1[k]){
esta = true
}
}
}
If it ever became true ... then it is in some position, and it does not work for us.
for(var j=0;j<datos2.length;j++){
var esta = false
for(var k=0;k<datos1.length;k++){
if(datos2[j]!=datos1[k]){
esta = true
}
}
if (esta){
datosNoRepetidos[j]=datos2[j];
}
}
Now .. we need something more .. dataNoRepetidos [j] is not right .. we have to keep saving in the last position of that array, not in the same position of the array that we are going through .. then .. let's add an accountant.
var pos = 0
for(var j=0;j<datos2.length;j++){
var esta = false
for(var k=0;k<datos1.length;k++){
if(datos2[j]!=datos1[k]){
esta = true
}
}
if (esta){
datosNoRepetidos[pos]=datos2[j];
pos = pos+1
}
}