Code Monkey home page Code Monkey logo

int-u5l1-23-24-student-exercises's Introduction

Lesson 5.1: Arrays

Arrays: Organizing Your Data

Imagine you have a pile of papers from school, and you need to organize them. That's where arrays come in!

What is a Data Structure?

A data structure is a way of organizing data so that it can be used effectively. Arrays are one such data structure that helps us organize information.

Declaring an Array

In JavaScript, we can declare an array like this:

let numbers = [5, 10, 15, 20, 25];
let fruits = ["Apple", "Banana", "Cherry", "Date", "Elderberry"];
let emptyArray = [];
  • Array elements are listed inside square brackets and separated by commas.

Array Elements

An array element is each individual value in an array. For example:

let artists = ["Beyoncé", "Drake", "Billie Eilish", "BTS", "Ariana Grande"];
  • Array name: artists
  • Array elements: ["Beyoncé", "Drake", "Billie Eilish", "BTS", "Ariana Grande"]

Using Arrays

Arrays are frequently used in websites, apps, and games. Examples include photo galleries, music playlists, shopping carts, and more.

Array Index

An array index is the location of an array element. The first array index is always 0.

Retrieving Elements by Index

You can retrieve a value from an array by using the array name followed by the index number in square brackets. For example:

let pets = ["guinea pig", "gecko", "bird", "cat", "snake"];
let favoritePet = pets[1];
console.log(favoritePet); // This prints "gecko"

Happy coding! 😊

int-u5l1-23-24-student-exercises's People

Contributors

cn-curriculum avatar cn-mika 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.