DEV Community

vishwa v
vishwa v

Posted on • Edited on

methods-4

JavaScript Array reduceRight()
The reduceRight() method runs a function on each array element to produce a single value.

The reduceRight() works from right-to-left in the array. See also reduce().

const numbers = [45, 4, 9, 16, 25];
let sum = numbers.reduceRight(myFunction);

function myFunction(total, value) {
  return total + value;
}
Enter fullscreen mode Exit fullscreen mode

JavaScript Array every()
The every() method checks if all array values pass a test.

const numbers = [45, 4, 9, 16, 25];
let allOver18 = numbers.every(myFunction);

function myFunction(value, index, array) {
  return value > 18;
}
Enter fullscreen mode Exit fullscreen mode

JavaScript Array some()
The some() method checks if some array values pass a test.

const numbers = [45, 4, 9, 16, 25];
let someOver18 = numbers.some(myFunction);

function myFunction(value, index, array) {
  return value > 18;
}
Enter fullscreen mode Exit fullscreen mode

JavaScript Array.from()
The from() method can return an array from any variable with a length property.

let text = "ABCDEFG";
Array.from(text);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)