This is my first time using google spreadsheets, and I'm trying to accomplish something in the functions. I know it's javascript (A language I'm not entirely familiar with). I'm trying to take a range from two tables, and get the intersection location of each, and fill in missing values for rows that already should exist.
For example, assuming the following two sheets:
Sheet1
+-----------+----------+--------+---------+
|   Fruit   |  Color   | Weight | isApple |
+-----------+----------+--------+---------+
| Banana    | Yellow   |      3 | no      |
| Orange    | Orange   |      3 | no      |
| Apple     | Red      |      2 | yes     |
| Pineapple | Brownish |      5 | no      |
+-----------+----------+--------+---------+
Sheet2
+-----------+----------+--------+---------+
|   Fruit   |  Color   | Weight | isApple |
+-----------+----------+--------+---------+
| Banana    |          |        |         |
| Apple     |          |        |         |
| Pear      |          |        |         |
| Watermelon|          |        |         |
+-----------+----------+--------+---------+
I want to find the intersections of the Fruit row, and fill in the color, weight, and isApple, of each one we know.
I wrote something I felt confident should work to get the intersection of range1, and it returns an empty array for some reason.  When I test this in Apps Script Editor, it seems to work fine.
//assuming range1 = Sheet1!A2:A5 and range2=Sheet2!A2:A5
function intersection(range1, range2) {
  var i = 0;
  var j = 0;
  var matches = new Array();
  while(i < range1.length){
    if(range2.toString().includes(range1[i].toString())){
      matches.push(i);
    }
    i++
  }
  return matches;
}
I would expect this to return an array of [0,2] since the 0th element Banana, and the 1st element Apple from Sheet1, exist in sheet 2.
I would then use that data to fill in the rows for Apple, and Banana from the information in Sheet2.
I'm not at that second part yet, since I can't seem to get the sheet to even find the intersection.
My end goal expected output would be that Sheet 2 is changed to:
Sheet2
+-----------+----------+--------+---------+
|   Fruit   |  Color   | Weight | isApple |
+-----------+----------+--------+---------+
| Banana    | Yellow   |      3 | no      |
| Apple     | Red      |      2 | yes     |
| Pear      |          |        |         |
| Watermelon|          |        |         |
+-----------+----------+--------+---------+
 
     
    
