Referencing this inside a callback can be tricky, since this refers to the context where the function is called, not where it is defined. To explicitly bind this to the defining context, use the bind() function:
To find the first element of an array satisfying some criteria, use Array.prototype.find(). If you just need the index, use .findIndex instead. (via StackOverflow)
var array1 = [5, 12, 8, 130, 44];
var found = array1.find(function(element) {
return element > 10;
// expected output: 12
Log the current stack to the console:
console.log(new Error().stack);
Last modified 1mo ago
Copy link