Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    JSJavaScript

    Getting started

    • What is JavaScript?
    • Variables: let, const and var
    • Data types
    • Type conversion

    Operators and strings

    • Arithmetic and assignment
    • Comparison and logic
    • Strings and template literals
    • String methods
    • Numbers and Math

    Control flow

    • Conditions: if and else
    • switch and the ternary operator
    • Loops: for and while
    • Challenge: FizzBuzz

    Functions

    • Functions
    • Arrow functions
    • Parameters: default, rest and spread
    • Scope and closures
    • Callbacks and higher-order functions

    Arrays

    • Array basics
    • map, filter and find
    • reduce and sorting
    • Destructuring

    Objects

    • Object basics
    • Copies and references
    • Methods and this
    • JSON and optional chaining

    Classes and OOP

    • Classes
    • Inheritance

    JavaScript in the page

    • Controlling the page (DOM)
    • Creating elements
    • Events
    • Forms and validation
    • Saving in the browser (localStorage)

    Errors and async

    • Handling errors: try and catch
    • Timers and the event loop
    • Promises
    • async and await
    • Fetching data from an API

    Practical tools and techniques

    • Searching with regular expressions
    • Cancellation and stale results
    • Testing and debugging JavaScript

    Modern JavaScript and a project

    • Map and Set
    • Dates and localised formatting
    • Modules: import and export
    • Project: a complete to-do app
    JavaScript

    Arrays · Lesson 19 of 45

    Array basics

    A list of values: add, remove and loop over it.

    8 minutes3 games

    An array is an ordered list in [ ]. Each item has a number (index) starting at 0, and items can be any type, even other arrays.

    langs =

    "HTML"[0]
    "CSS"[1]
    "JS"[2]

    langs[2] is "JS" and langs.length is 3. The last item is always langs[langs.length - 1].

    MethodWhat it does

    push(x)

    adds to the end

    pop()

    removes and returns the last item

    unshift(x)

    adds to the start

    shift()

    removes the first item

    includes(x)

    is it there?

    indexOf(x)

    its index (or -1)

    slice(a, b)

    a copy of a part

    splice(i, n)

    removes n items at i (changes the original)

    join(sep)

    turns it into text

    Step by step1 / 5
    1. ▶const cart = ["pen"]
    2. 2cart.push("book")
    3. 3cart.unshift("bag")
    4. 4const last = cart.pop()
    5. 5console.log(cart, last)

    Variables

    cart["pen"]

    Output

    …
    JavaScript
    const langs = ["HTML", "CSS", "JS"]
    
    for (const lang of langs) {
      console.log("I learn", lang)
    }
    
    langs.forEach((lang, i) => console.log(i, lang))
    console.log(langs.join(" + "))

    Important

    for...of gives you the items; for...in gives you the indexes as strings. For arrays use for...of or forEach.

    Interview question

    How do you remove duplicates from an array?

    What's the output?

    const a = [3, 6, 9]
    console.log(a[1])
    console.log(a.length)

    What will this code print?

    Complete the code

    Add "Go" to the end and remove the first item.

    const langs = ["C", "Java"]
    langs.("Go")
    langs.()

    Exercise

    Print the last item ("Python") without writing its index.

    Expected output: Python

    JavaScript
    const langs = ["HTML", "CSS", "JS", "Python"]
    

    Learn more from

    • javascript.info: Arraysjavascript.info
    • MDN: Arraydeveloper.mozilla.org

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousCallbacks and higher-order functionsNextmap, filter and find
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.