The findIndex() method returns the index of the first element in an array that meets the criteria specified in a test function.
For example, this code finds the index of the first element that is greater than 18:
const numbers = [4, 9, 16, 25, 29]; let first = numbers.findIndex(myFunction); function myFunction(value, index, array) { return value > 18; } |
Keep in mind that the function accepts three arguments:
ES6 introduced the following methods to the Math object:
The Math.trunc(x) method returns the integer portion of x, removing any fractional digits.
Math.trunc(4.9); // returns 4 Math.trunc(4.7); // returns 4 Math.trunc(4.4); // returns 4 Math.trunc(4.2); // returns 4 Math.trunc(-4.2); // returns -4 |
The Math.sign(x) method returns the sign of x, indicating whether it is negative, zero, or positive.
Math.sign(-4); // returns -1 Math.sign(0); // returns 0 Math.sign(4); // returns 1 |
The Math.cbrt(x) method returns the cube root of x.
Math.cbrt(8); // returns 2 Math.cbrt(64); // returns 4 Math.cbrt(125); // returns 5 |
The Math.log2(x) method returns the logarithm of x with base 2.
Math.log2(2); // returns 1 |