Skip to content

Instantly share code, notes, and snippets.

@rs77
Last active August 29, 2015 14:21
Show Gist options
  • Save rs77/37eae99da0f600aeb588 to your computer and use it in GitHub Desktop.
Save rs77/37eae99da0f600aeb588 to your computer and use it in GitHub Desktop.
This function is handy when working with Google App Script for Spreadsheets and you need to get an array out of the 2-dimensional getValues() call. In fact, you may want to look at this performance test and see that running indexOf on array data may be quite slow in comparison to their for-loop and while-loop counterparts as seen here: http://js…
function findElem( el ) {
return !!~el.indexOf( this.val );
}
// for example:
var arr = [ [ 18, "AAA" ], [ 19, "BBB" ], [ 20, "CCC" ] ];
var query = 19;
console.log( arr.filter( findElem, { val: query } ) ); // returns [[19, "BBB"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment