Skip to main content

construct key-value pair

Construct a key-value pair

Holly Conrad Smith avatar
Written by Holly Conrad Smith
Updated over a month ago

Category: Objects

Kind: Operation

Description: Construct a key-value pair

Inputs

Name

Abbreviation

Type

Access

Description

Key

K

String

Item

The key of the pair

Value

V

Any

Item

The value of the pair

Outputs

Name

Abbreviation

Type

Access

Description

Pair

P

Object

Item

The constructed key-value pair


About key-value pairs

A key-value pair is a fundamental concept in programming and data storage, especially in dictionaries, maps, JSON, and databases.

Basic Idea:

A key-value pair consists of:

  • Key: A unique identifier.

  • Value: The data or information associated with that key.

Example in Real Life:

Think of a dictionary (the book):

  • The word is the key.

  • The definition is the value.

If you look up the key "apple" in the dictionary, the value might be "a fruit that grows on trees".

Example

Take, for example, a real estate listing. It might be stored like this:

property_listing = { "address": "123 Maple Street", "price": 450000, "bedrooms": 3, "bathrooms": 2, "square_feet": 1800, "status": "For Sale" }

Breakdown of key-value pairs:

KEY

VALUE

address

123 Maple Street

price

450000

bedrooms

3

bathrooms

2

square_feet

1800

status

For Sale

Each key describes a property attribute, and each value holds the actual data about it.

This kind of structure is super common in databases, and APIs—makes it easy to store, access, and filter lists.

Object entries refer to the key-value pairs within an object. In JavaScript (and similar structures like JSON), these are called entries because each one is a single unit of information: a key and its corresponding value.

Let’s say you have a JavaScript object:

javascript CopyEdit const property = {   address: "123 Maple Street",   price: 450000,   bedrooms: 3 };

The entries of this object are:

  • ["address", "123 Maple Street"]

  • ["price", 450000]

  • ["bedrooms", 3]


How-To

  1. Feed in a string to define the key or name of the property

    You can use a string, panel, or the result of any other node that outputs a string

  2. Feed in any data type as the “value”

    You could use string, number, Boolean, or any single value

  3. The result is a key-value pair object

  4. To create multiple key-value pairs from lists, use map

Did this answer your question?