Google Script – How to find the index of a nested Array in the search Array?

I want to find the index of the NestedArray (userdata) inside the SearchArray (data). I already have the existing code inserted below.

var data = [["John",25],["James",19],["Liam",27],["George",22]]
var user = "Liam";
var userdata = [];

const userfound = data.some(function(row){
    if(row[0] == user){ 
      userdata = row; 
      return true;
    else {return false;}


The code above gives the corresponding log:

Array [Array ["John", 25], Array ["James", 19], Array ["Liam", 27], Array ["George", 22]]
Array ["Liam", 27]

normally I would try to find an index of an item in an Array like so:

const index = data.findIndex( x => userdata.includes(x)); 

However this doesn't work for a 2d Array. Does anyone have a clue?

Read more here:

Content Attribution

This content was originally published by SmexyKoen at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: