Get startedGet started for free

Creating associative arrays

Associative arrays are powerful constructs to use in your Bash scripting. They are very similar to 'normal' arrays, however they have a few important differences in their creation, manipulation and key properties.

Associative arrays allow you to index using words rather than numbers, which can be important for ease of inputting and accessing properties. For example, rather than accessing 'index 4' of an array about a city's information, you can access the city_population property, which is a lot clearer!

In this exercise we will practice creating and adding to an associative array. We will then access some special properties that are unique to associative arrays. Let's get started!

NOTE: if you submit incorrect code, you may need to refresh the browser to remove old variables etc that affect the test suite before submitting again

This exercise is part of the course

Introduction to Bash Scripting

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create empty associative array
declare ____ ____

# Add the key-value pairs
model_metrics[____]=____
model_metrics____=____
model_metrics____=____
Edit and Run Code