Whatever message this page gives is out now! Go check it out!

Struct.entries

Last update:
May 18, 2026
Returns an array of key–value pairs from a struct, where each entry is a two-element array containing the key and value.

Description

The Struct.entries() member function provides a convenient way to work with a struct’s contents as an array of key–value pairs.
Each element in the returned array is a two-element array where:
  • Position 1 is the key (string)
  • Position 2 is the value
This simplifies iteration and transformation of struct data.

Member function syntax

struct.entries()

Returns

Array: An array of two-element arrays representing key–value pairs.

Usage Notes

  • Each entry is an array: [key, value].
  • Iteration order follows struct enumeration order (not guaranteed alphabetical).
  • Useful with array functions like map(), filter(), and reduce().

Basic usage


<cfscript>
user = { name="Alice", age=30, city="Paris" };
entries = user.entries();
writeDump(entries);
</cfscript>

Iterating Over Keys and Values


<cfscript>
    settings = { theme="dark", language="en", itemsPerPage=20 };
    entries=settings.entries();
    //writedump(entries)
    for (entry in entries) {
        writeOutput("#entry.key# = #entry.value#<br>");
    }
</cfscript>

Transforming Struct to Label/Value Array


<cfscript>
    product = { id="P-123", name="Coffee Mug", price=12.5 };

    labels = product.entries().map(pair => {
        return { label = uCase(pair.key), value = pair.value };
    });

    writeDump(labels);
</cfscript>

Filtering Struct Entries


<cfscript>
    config = { dbHost="localhost", dbPassword="secret", dbUser="admin", debugMode=true };

    filtered = config.entries().filter(pair => pair.key.startsWith("db"));

    result = {};
    for (pair in filtered) {
        result[pair.key] = pair.value;
    }

    writeDump(result);
</cfscript>

Convert Struct to Key=Value Lines


<cfscript>
    env = { APP_NAME="MyApp", LOG_LEVEL="INFO", PORT=8080 };

    lines = env.entries().map(pair => pair.key & "=" & pair.value);

    text = arrayToList(lines, chr(10));
    writeOutput(text);
</cfscript>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page