Skip to content

Instantly share code, notes, and snippets.

@rs77
Last active August 29, 2015 14:21
Show Gist options
  • Save rs77/b2c51c943e3b3926a8fa to your computer and use it in GitHub Desktop.
Save rs77/b2c51c943e3b3926a8fa to your computer and use it in GitHub Desktop.
This function is handy when working within Google Apps Script for Spreadsheets are you are operating with a 2-dimensional array. If you need to pop out an element within an array then this function works best. Need to use the array ".filter" method and call the removeElem callback function passing in the arguments as the second parameter: (In fa…
function removeElem( el ) {
return !~el.indexOf( this.val );
}
// for example:
var arr = [ [ 18, "AAA" ], [ 19, "BBB" ], [ 20, "CCC" ] ];
var query = 19;
console.log( arr.filter( removeElem, { val: query } ) ); // returns [[18, "AAA"],[20,"CCC"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment