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)
Create and Access Elements
Create an array named
fruitscontaining:"apple","banana","mango","orange","grapes".Print the second fruit from the array.
Add Element to End
Using
.push(), add"pineapple"to the end of thefruitsarray.Print the updated array.
Remove First Element
Using
.shift(), remove the first element fromfruits.Print the removed element and the updated array.
Find Element Index
Find the index of
"mango"in thefruitsarray using.indexOf()and print it.
Reverse an Array
Given an array:
let letters = ["a", "b", "c", "d", "e"]Reverse the array and print the result.
Sort Numbers
Given:
let numbers = [40, 10, 100, 30, 5]Sort this array in ascending order and print it.
Loop Through Array
Loop through the array
fruitsand print each fruit using aforloop.
Check Existence
Check if
"banana"exists infruitsusing.includes()and printtrueorfalse.
Merge Arrays
Given:
let arr1 = [1, 2],let arr2 = [3, 4]Merge them into a single array using
.concat()or spread operator[...].
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)
Create an Object
Create an object
personWith the following keys:
Access Object Properties
Access and print the value of
namefrom thepersonobject using dot notation.
Update Object Properties
Change the
ageof thepersonobject to30.
Add New Property
Add a new property
genderwith the value"male"to thepersonobject.
Delete Property
Remove the
cityproperty from thepersonobject using thedeleteoperator.
Check for Property
Check if the key
"email"exists in thepersonobject using theinkeyword orhasOwnProperty.
Loop Through Properties
Loop through all keys and values in the
personobject using afor...inloop and print each pair.
Get All Keys
Use
Object.keys(person)to get an array of all keys and print it.
Get All Values
Use
Object.values(person)to get an array of all values and print it.
Array of Objects
Create an array
usersof 3 user objects, each havingnameandemail.Print the names of all users using a loop.
