Advanced JavaScript Training
Common Array Methods

Common Array Methods

  <p class='lg:w-1/2 w-full leading-relaxed text-gray-500 w-1/2 p-0.5' style='text-align: left; margin-right: 1in;'>
       <p style='text-align: left;'> JavaScript provides powerful array methods like map, filter, and reduce for more advanced operations.</p>
  • map: Creates a new array by applying a function to each element.
  • filter: Returns a new array containing elements that meet a specified condition.
  • reduce: Reduces the array to a single value using a callback function.
<pre style='text-align: left;'>

let numbers = [1, 2, 3, 4, 5]; let squared = numbers.map(function(number) { return number * number; });

  
    let evenNumbers = numbers.filter(function(number) {
    return number % 2 === 0;
   });
    
  
    let sum = numbers.reduce(function(total, number) {
    return total + number;
   }, 0);
    
 
Have a doubt?
Post it here, our mentors will help you out.