Search⌘ K

Manipulating Arrays

Explore the fundamental techniques for manipulating arrays in JavaScript, including adding and removing elements at both ends and modifying values by index. This lesson helps you understand practical array operations to prepare you for more advanced JavaScript coding.

Adding elements to the beginning or end

You can add elements to the beginning and to the end of the array:

  • Push adds elements to the end of the array
  • Unshift adds elements to the beginning of the array
Node.js
let days=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
days.push( 'Saturday' );
console.log("Saturday is added to the end by the push() function\n", days );
days.unshift( 'Sunday' );
console.log("Sunday is added to the beginning by the unshift() function\n", days );

Removing elements

...