Giter Site home page Giter Site logo

flw2-u1l4-23-24-student-exercises's Introduction

Lesson 1.4: Arrays & Objects

๐Ÿ“Œ Key Concepts:

1. Arrays

  • Definition: An array is a data structure in JavaScript used to store multiple values in a single variable.

    let fruits = ["apple", "banana", "cherry"];
  • Index: Each item in an array is assigned a number starting from 0, which is called its index.

    fruits[0];  // "apple"
  • Length: You can find out how many items are in an array with .length.

    fruits.length;  // 3
  • Array Methods:

    • .push(): Add an element to the end.

    • .pop(): Remove the last element.

    • .join(): Combine all elements into a string.

    • .splice(): Add or remove elements from the array.

      fruits.push("grape");  // Adds "grape" to the end
      fruits.pop();          // Removes the last item ("grape")

2. Objects

  • Definition: Objects are collections of key-value pairs. They help associate different values together.

    let book = {
      title: "Harry Potter",
      author: "J.K. Rowling",
      published: 1997
    };
  • Properties: The keys in an object (like title, author, etc. in the above example) are called properties.

  • Accessing Values: Use dot notation to access values in an object.

    book.title;  // "Harry Potter"
  • Arrays in Objects: Objects can hold arrays as values.

    let student = {
      name: "Alice",
      subjects: ["Math", "Science", "English"]
    };
    student.subjects[1];  // "Science"

๐Ÿง  Remember:

  1. Arrays are ordered lists, and you can access any element by its index.
  2. Objects store data as key-value pairs and are great for representing entities with various attributes.
  3. Always use the right data structure for your needs; sometimes, you might even use arrays and objects together!

๐Ÿ’ก Tips:

  • Always comment your code! It helps in understanding what each part of the code does.

    // This is a single line comment in JavaScript
  • If you're unsure about a method or property, search online or revisit this README.

Happy coding!

flw2-u1l4-23-24-student-exercises's People

Contributors

cn-curriculum avatar cn-mika avatar jayhtang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.