Basic JavaScript Practice: Arrays & Objects (20 Questions)

Last Updated: June 23, 2025

JavaScript is one of the most popular and beginner-friendly programming languages used in web development today. Two of its most fundamental building blocks are arrays and objects—data structures that help developers store, organize, and manipulate data efficiently. Whether you’re just starting out or brushing up on your basics, mastering arrays and objects is crucial for writing clean, functional JavaScript code. In this article, we’ve compiled 20 hands-on practice questions that will guide you through common operations like accessing elements, updating values, looping through structures, and combining data. These exercises are perfect for beginners looking to solidify their understanding through real-world examples.

Array Practice (1–10)

  1. Create and Access Elements

    • Create an array named fruits containing: "apple", "banana", "mango", "orange", "grapes".

    • Print the second fruit from the array.

  2. Add Element to End

    • Using .push(), add "pineapple" to the end of the fruits array.

    • Print the updated array.

  3. Remove First Element

    • Using .shift(), remove the first element from fruits.

    • Print the removed element and the updated array.

  4. Find Element Index

    • Find the index of "mango" in the fruits array using .indexOf() and print it.

  5. Reverse an Array

    • Given an array: let letters = ["a", "b", "c", "d", "e"]

    • Reverse the array and print the result.

  6. Sort Numbers

    • Given: let numbers = [40, 10, 100, 30, 5]

    • Sort this array in ascending order and print it.

  7. Loop Through Array

    • Loop through the array fruits and print each fruit using a for loop.

  8. Check Existence

    • Check if "banana" exists in fruits using .includes() and print true or false.

  9. Merge Arrays

    • Given: let arr1 = [1, 2], let arr2 = [3, 4]

    • Merge them into a single array using .concat() or spread operator [...].

  10. Sum of Numbers

    • Given: let nums = [5, 10, 15, 20]

    • Use a loop or .reduce() to find and print the total sum of the elements.

Object Practice (11–20)

  1. Create an Object

    • Create an object person With the following keys:

      js
      {
      name: "John",
      age: 25,
      city: "Delhi"
      }
  2. Access Object Properties

    • Access and print the value of name from the person object using dot notation.

  3. Update Object Properties

    • Change the age of the person object to 30.

  4. Add New Property

    • Add a new property gender with the value "male" to the person object.

  5. Delete Property

    • Remove the city property from the person object using the delete operator.

  6. Check for Property

    • Check if the key "email" exists in the person object using the in keyword or hasOwnProperty.

  7. Loop Through Properties

    • Loop through all keys and values in the person object using a for...in loop and print each pair.

  8. Get All Keys

    • Use Object.keys(person) to get an array of all keys and print it.

  9. Get All Values

    • Use Object.values(person) to get an array of all values and print it.

  10. Array of Objects

    • Create an array users of 3 user objects, each having name and email.

      js
      let users = [
      {
      name: "Alice",
      email: "alice@example.com"
      },
      {
      name: "Bob",
      email: "bob@example.com"
      },
      {
      name: "Charlie",
      email: "charlie@example.com"
      }
      ];
    • Print the names of all users using a loop.