Skip to content

itscodenation/int-u5l2-23-24-student-exercises

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lesson 5.2: Array Methods & Properties

Overview

Arrays in JavaScript are used to store multiple values in a single variable. They are a fundamental aspect of managing collections of data.

Array Properties

  • Length: Determines the number of elements in an array.
    const arr = [1, 2, 3];
    console.log(arr.length); // Output: 3

Manipulating Arrays

Adding Elements

  • push(): Adds one or more elements to the end of an array and returns the new length.

    arr.push(4); // Adds 4 to the end
  • unshift(): Adds one or more elements to the beginning of an array and returns the new length.

    arr.unshift(0); // Adds 0 to the start

Removing Elements

  • pop(): Removes the last element from an array and returns that element.

    arr.pop(); // Removes the last element
  • shift(): Removes the first element from an array and returns that element.

    arr.shift(); // Removes the first element

This guide covers the basics of array manipulation in JavaScript, focusing on commonly used methods and properties. Understanding these will significantly aid in data handling and manipulation tasks in your projects. Practice these methods to become proficient in managing arrays efficiently.

Happy coding! 😊

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published