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 Arrays in JavaScript

    high-level programming language

    High-level programming language.

    Arrays are a fundamental part of JavaScript and are used to store multiple values in a single variable. They are incredibly versatile and are used in almost every JavaScript application. This article will cover the basics of creating, accessing, and modifying arrays in JavaScript.

    Creating Arrays

    In JavaScript, arrays can be created in two ways:

    1. Array Literals: This is the most common way to create an array. An array literal is defined by enclosing a comma-separated list of values in square brackets [].
    let fruits = ['apple', 'banana', 'cherry'];
    1. Array Constructor: Although less common, arrays can also be created using the new keyword and the Array() constructor.
    let fruits = new Array('apple', 'banana', 'cherry');

    Accessing Array Elements

    Array elements are accessed using their index number. The index of an array is zero-based, meaning the first element is at index 0, the second element is at index 1, and so on.

    let fruits = ['apple', 'banana', 'cherry']; console.log(fruits[0]); // Outputs: apple

    Modifying Array Elements

    You can modify an existing element in an array by referring to the index number.

    let fruits = ['apple', 'banana', 'cherry']; fruits[1] = 'blueberry'; console.log(fruits); // Outputs: ['apple', 'blueberry', 'cherry']

    Understanding the Length Property

    The length property of an array returns the number of elements in the array. It is useful when you want to know the size of the array.

    let fruits = ['apple', 'banana', 'cherry']; console.log(fruits.length); // Outputs: 3

    Multidimensional Arrays

    JavaScript allows for arrays of arrays, also known as multidimensional arrays. This is useful when you want to store tables of data.

    let matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; console.log(matrix[1][2]); // Outputs: 6

    In conclusion, arrays are a powerful tool in JavaScript. They allow you to store multiple values in a single variable, and provide numerous methods and properties to work with those values. Understanding arrays is fundamental to becoming proficient in JavaScript.

    Test me
    Practical exercise
    Further reading

    Buenos dias, any questions for me?

    Sign in to chat
    Next up: Array methods