101.school
CoursesAbout
Search...⌘K
Generate a course with AI...

    JavaScript 101

    Receive aemail containing the next unit.
    • Introduction to JavaScript
      • 1.1What is JavaScript?
      • 1.2Setting up your environment
      • 1.3Basic syntax and variables
    • Data Types and Variables
      • 2.1Understanding data types
      • 2.2Variables and constants
      • 2.3Operators
    • Control Structures
      • 3.1Conditional statements
      • 3.2Loops
      • 3.3Error handling
    • Functions
      • 4.1Defining functions
      • 4.2Function expressions
      • 4.3Arrow functions
    • Objects and Arrays
      • 5.1Understanding objects
      • 5.2Understanding arrays
      • 5.3Array methods
    • Document Object Model (DOM)
      • 6.1What is the DOM?
      • 6.2Selecting and manipulating elements
      • 6.3Event handling
    • Asynchronous JavaScript
      • 7.1Callbacks
      • 7.2Promises
      • 7.3Async/Await
    • API Interaction
      • 8.1What is an API?
      • 8.2Fetch API
      • 8.3Working with JSON
    • Debugging
      • 9.1Console methods
      • 9.2Debugging tools
      • 9.3Common JavaScript errors
    • JavaScript Libraries
      • 10.1Introduction to libraries
      • 10.2Using jQuery
      • 10.3Using lodash
    • JavaScript Frameworks
      • 11.1Introduction to frameworks
      • 11.2Using React
      • 11.3Using Vue.js
    • Testing and Deployment
      • 12.1Writing tests with Jest
      • 12.2Deployment with Netlify
      • 12.3Continuous integration
    • Final Project
      • 13.1Project proposal
      • 13.2Project development
      • 13.3Project presentation

    Objects and Arrays

    Understanding Array Methods in JavaScript

    high-level programming language

    High-level programming language.

    In JavaScript, arrays are used to store multiple values in a single variable. They are incredibly versatile and come with a wide range of built-in methods that allow us to manipulate and interact with them in various ways. This article will provide an overview of some of the most commonly used array methods in JavaScript.

    Adding and Removing Elements

    JavaScript provides several methods for adding and removing elements from an array:

    • push(): This method adds one or more elements to the end of an array and returns the new length of the array.
    • pop(): This method removes the last element from an array and returns that element.
    • shift(): This method removes the first element from an array and returns that element.
    • unshift(): This method adds one or more elements to the beginning of an array and returns the new length of the array.

    Searching an Array

    There are also several methods that allow us to search for elements within an array:

    • indexOf(): This method returns the first index at which a given element can be found in the array, or -1 if it is not present.
    • find(): This method returns the first element in the array that satisfies a provided testing function, or undefined if no such element is found.
    • findIndex(): This method returns the index of the first element in the array that satisfies a provided testing function, or -1 if no such element is found.

    Iterating Over an Array

    JavaScript provides several methods for iterating over an array and applying a function to each element:

    • forEach(): This method executes a provided function once for each array element.
    • map(): This method creates a new array with the results of calling a provided function on every element in the array.
    • filter(): This method creates a new array with all elements that pass a test implemented by a provided function.
    • reduce(): This method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.

    Sorting and Reversing Arrays

    • sort(): This method sorts the elements of an array in place and returns the array. The default sort order is built upon converting the elements into strings, then comparing their sequences of UTF-16 code unit values.
    • reverse(): This method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.

    Array Destructuring

    Array destructuring is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables. This can be particularly useful when you want to extract multiple values from an array in a single operation.

    In conclusion, JavaScript provides a rich set of array methods that make it easy to manipulate and interact with arrays. By understanding and using these methods, you can write more efficient and readable code.

    Test me
    Practical exercise
    Further reading

    Buenos dias, any questions for me?

    Sign in to chat
    Next up: What is the DOM?