Advanced JavaScript Training
Modifying Arrays

Modifying Arrays

  <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 offers several compelling reasons for its use in web development and beyond:</p>
  • Push: Adds one or more elements to the end of an array.
  • Pop: Removes and returns the last element of an array.
  • Shift: Removes and returns the first element of an array.
  • Unshift: Adds one or more elements to the beginning of an array.
  
     let numbers = [1, 2, 3];
    numbers.push(4); // Adds 4 to the end
    numbers.pop(); // Removes and returns 4 
    numbers.unshift(0); // Adds 0 to the beginning
    numbers.shift(); // Removes and returns 0
    
 
Have a doubt?
Post it here, our mentors will help you out.