Inventory update problem

Hey Guys
I tried to work on this challenge but it seems that doesn’t work
what’s wrong with my code?

function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
    for (var i = 0; i < arr1.length; i++) {
      for (var j = 0; j < arr1[i].length; j++) {
        for (var k = 0; k < arr2.length; k++) {
        arr1.forEach(function(item) {
          if (arr1.indexOf(arr1[i][j]) > 0 && arr2[k].indexOf(item) > 0) {
            arr2[k][item].push(arr1[i][j]);
            return arr1;
          }
        });
        }
        
      }
    }
    return arr1;
}




// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);

Surround your code in backticks ```

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

Using the following example inventory lists, both of the above if statement conditions are evaluating evaluating to -1, so the if statement evaluates to false and nothing gets pushed to arr2[k][item].

The first condition will always return false, because you are attempting to find an element in arr1 which is a number. The problem is arr1 is an array of arrays and not an array of numbers. For example, when i=0, j=0, and k=0 arr1 is the following:

[ [ 21, 'Bowling Ball' ],
  [ 2, 'Dirty Sock' ],
  [ 1, 'Hair Pin' ],
  [ 5, 'Microphone' ] ]

and arr1[0][0] is 21, so your first indexOf is trying to find an index in arr1 which has the value 21. Since the elements in arr1 are arrays, they will never equal the value 21.

function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
    for (var i = 0; i < arr1.length; i++) {
      for (var j = 0; j < arr1[i].length; j++) {
        for (var k = 0; k < arr2.length; k++) {
        arr2[k].forEach(function(item) {
          if (!arr2[k].includes(arr1[i])) {
            arr1.push(arr2[k]);
            return arr1;
          }
        });
        }

      }
    }
    arr1.sort(function(a , b) {
        if (a[1] > b[1] ) {
            return 1;
        } 
        if (a[1] < b[1]) {
            return -1;
        }
        return 0;
    });
    return arr1;
}

Thanks alot for your response I got what you mean by that I tried to turn on another way but kept using forEach I tried to use includes against the second array to see if it exists there or not but that seems that doesn’t work it works in first and third option but not the other
can you help me in this please
Thanks