Difference between two arrays

**I want to return the differnce between two arrays but my code is returning an empty array. I think am close but there is a bug somewhere. please help me out!

  **Your code so far**

function diffArray(arr1, arr2){
var pushArr=[];
for(var i=0; i<arr1.length; i++){
  for(var j=0; j<arr2.length; j++){
      return pushArr.push(arr1[i]);
    }else if(arr2[j]!==arr1[i]){
      return pushArr.push(arr2[j]);
      return pushArr;

console.log(diffArray([1, 2, 3, 4,5], [1, 2, 3, 5]));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Linux; U; Android 7.0; TECNO P701 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/88.0.4324.181 Mobile Safari/537.36 OPR/54.0.2254.56148.

Challenge: Diff Two Arrays

Link to the challenge:

1 Like

Remember that return is a special command that signals the end of the function. As soon as a return is hit, nothing else will happen.

1 Like

I thought declaring a return statement in the if…else block wont affect the loop. if that is the case, i dont have to return in the if…else block right?

Right. You only want to return at the end.

Okay let me do some corrections. i will share my result.

I used another format to pass the challenge. Thank you