# Creating Single and Multi-Dimensional Arrays

Practice Labs Module
Time
18 minutes
Difficulty
Intermediate

Welcome to the "Creating Single and Multi-Dimensional Arrays" Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.

Join over 3 million cybersecurity professionals advancing their career
or

Overview

### Introduction

Welcome to the Creating Single and Multi-Dimensional Arrays Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.

### Exam Objectives

The following exam objective is covered in this lab:

• 2.2 Declare and use arrays

### Lab Duration

It will take approximately 20 minutes to complete this lab.

### Exercise 1 - Creating Arrays

A variable declared in JavaScript can store a single value, but what if you want to store multiple values in a single variable? Well, you may have to use an array. In JavaScript, an array can store multiple values at a time. There are two types of arrays, single-dimensional and multi-dimensional.

In a single-dimensional array, you will have one row and multiple columns. You can identify each value stored in an array with the help of an index number. An index number within an array starts at 0. Therefore, the first element in an array is [0], the second element is [1], the third element is [2], and so on. You can traverse within an array with the help of loops.

In a multi-dimensional array, you will have multiple rows and multiple columns. A multi-dimensional array has multiple rows and columns. It is an array of arrays. You can consider a multi-dimensional array as a matrix where you can store data in rows and columns. You can display the multi-dimensional array data in a tabular format. In JavaScript, you need to use a nested for loop to work with multi-dimensional arrays.

In this exercise, you will learn how to create both single-dimensional and multi-dimensional arrays with fixed values. You will traverse within the arrays with the help of for, while, and nested for loops.

The first task in this exercise will be to create a new folder named StudentList on PLABWIN10 desktop, add the folder to a Visual Studio Code workspace, and save the workspace with the name StudentList. You will create a new HTML page named StudentList.html in the StudentList workspace.

In the second task, you will write JavaScript code to create a single-dimensional array in StudentList.html. You will embed the code in the HTML page and run the page in Google Chrome web browser.

In the third task, you will create a new HTML page named MarkList.html in the StudentList workspace. You will write JavaScript code to create a multi-dimensional array in MarkList.html. You will embed the code in the HTML page and run the page in Google Chrome web browser.

### Learning Outcomes

After completing this exercise, you will be able to:

• Create single-dimensional and multi-dimensional arrays in JavaScript
Learning Partner
Comprehensive Learning

See the full benefits of our immersive learning experience with interactive courses and guided career paths.