Whatever message this page gives is out now! Go check it out!
Struct.entries() member function provides a convenient way to work with a struct’s contents as an array of key–value pairs.1 is the key (string)2 is the valuestruct.entries()[key, value].map(), filter(), and reduce().
<cfscript>
user = { name="Alice", age=30, city="Paris" };
entries = user.entries();
writeDump(entries);
</cfscript>
<cfscript>
settings = { theme="dark", language="en", itemsPerPage=20 };
entries=settings.entries();
//writedump(entries)
for (entry in entries) {
writeOutput("#entry.key# = #entry.value#<br>");
}
</cfscript>
<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>
<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>
<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>