> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structreduce.md).

# StructReduce

Run the provided udf against struct to reduce the values to a single output

## Method Signature

```
StructReduce(struct=[structloose], callback=[function], initialValue=[any])
```

### Arguments

| Argument       | Type       | Required | Description                                                                                                                                                                                                                                   | Default |
| -------------- | ---------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `struct`       | `struct`   | `true`   | The struct to reduce                                                                                                                                                                                                                          |         |
| `callback`     | `function` | `true`   | <p>The function to invoke for each entry in the struct. The function will be passed 4 arguments: the accumulator, they entry key,<br>the<br>current index, and the original struct. The function should return the new accumulator value.</p> |         |
| `initialValue` | `any`      | `false`  | The initial value of the accumulator                                                                                                                                                                                                          |         |

## Examples

### Script Syntax

[Run Example](https://try.boxlang.io/?code=eJxVjkGrwjAQhM%2FmVywpPFooeLc1IAgePAgelHfMM8sztCZlzVpE%2FO8mqQjeZj9mZoe0dX9%2BhCU8QMzkHo2EBcjjGcnLOpIdafePGW416U5n%2Bot978eJ%2BvGsbaYbQnRva6fJdlaKZyPYxvprID6F2M8nLIGmtzWUsHJ3GAhv1vP1oHvGOqMO75O4JQYVLBU8xIwwMLnvAPyAbE1QRcwU7Tyq1hhV5GC6jZKNeNbJ1CsZq5J%2FnnQjRrIB13wZPpugetMdh4FDCXF%2BRC%2BVH1oX)

```java
rainbow = { 
	"Red" : "Whero",
	"Orange" : "Karaka",
	"Yellow" : "Kowhai",
	"Green" : "Kakariki"
};
ui = structReduce( rainbow, ( Any previousValue, Any key, Any value ) => {
	return previousValue & "<dt>#key#</dt><dd>#value#</dd>";
}, "<dl>" ) & "</dl>";
writeDump( rainbow );
writeOutput( ui );

```

### Using Member Function

[Run Example](https://try.boxlang.io/?code=eJxVjsEKwjAQRM%2FmK5YUpELRu60BQfDgQfCgeIxm0dCalDWxlOK%2Fm6R68Db7mJkdktpcbAcrGIBN%2BAEVhyXw0x3J8iKQPUlzwwR3kmQtEz1j09hupLa7S53olhDN11pL0rXm7F0yr0M9jY%2FmhMpfMYcc1qaHlvClrX8eZeOxSKjGfhSvyGAGKwEDmxA6T%2BY%2FAFPglXIiC5msWgRVKSWyFIy3Erxk7yKaGsFDVfQvoi5ZR9rhxj%2Fa%2FDcNZl%2B69671LoewO6AP1rdXdA%3D%3D)

```java
rainbow = { 
	"Red" : "Whero",
	"Orange" : "Karaka",
	"Yellow" : "Kowhai",
	"Green" : "Kakariki"
};
ui = rainbow.reduce( ( Any previousValue, Any key, Any value ) => {
	return previousValue & "<dt>#key#</dt><dd>#value#</dd>";
}, "<dl>" ) & "</dl>";
writeDump( rainbow );
writeOutput( ui );

```

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJx1kNFLwzAQxp%2Bbv%2BLIg3RQ1ndrB2UUKY5N1k2Zb7E9XVjaSNpszNH%2F3STtlCq%2BfZf73eX7jtW8YqKBGC5AvPnqGW7hQjxvucry1GhaSUkD85BnL64WTL0jJV5nHh%2Bz%2B9%2B45PVhxFdYcl0NA%2FNk82c%2FytNooDF%2BhOVJF5FSVx8%2BCPaKIqaJEMB6vzSAI1PxUMEkIr3M6jdpsuSt0kW7xlIX6F9nAvAhqc%2BgsNGiDZw%2B4LkXRyY0wgTimbWnsNWqBhNVV1i3zXSd5tvFBm6A3gk%2Bo0b89B7SnWtoMbPNpeQNmhwj5ilZbNNpH9qyoQEtnPPPf1h3jm80tMutohHpgv4zauw6wOqIhCHke3ka4hEs9vIa3V3F3OgLFw2MlQ%3D%3D)

```java
animals = { 
	COW : {
		NOISE : "moo",
		SIZE : "large"
	},
	PIG : {
		NOISE : "oink",
		SIZE : "medium"
	},
	CAT : {
		NOISE : "meow",
		SIZE : "small"
	}
};
dump( label="All animals", var=animals );
animalInfo = StructReduce( animals, ( Any result, Any key, Any value ) => {
	return arguments.RESULT & "<li>" & arguments.KEY & "<ul><li>Noise: " & arguments.VALUE.NOISE & "</li><li>Size: " & arguments.VALUE.SIZE & "</li></ul></li>";
}, "<ul>" ) & "</ul>";
// Show result
echo( animalInfo );

```

## Related

* [StructAppend](/boxlang-language/reference/built-in-functions/struct/structappend.md)
* [StructClear](/boxlang-language/reference/built-in-functions/struct/structclear.md)
* [StructCopy](/boxlang-language/reference/built-in-functions/struct/structcopy.md)
* [StructDelete](/boxlang-language/reference/built-in-functions/struct/structdelete.md)
* [StructEach](/boxlang-language/reference/built-in-functions/struct/structeach.md)
* [StructEquals](/boxlang-language/reference/built-in-functions/struct/structequals.md)
* [StructEvery](/boxlang-language/reference/built-in-functions/struct/structevery.md)
* [StructFilter](/boxlang-language/reference/built-in-functions/struct/structfilter.md)
* [StructFind](/boxlang-language/reference/built-in-functions/struct/structfind.md)
* [StructFindKey](/boxlang-language/reference/built-in-functions/struct/structfindkey.md)
* [StructFindValue](/boxlang-language/reference/built-in-functions/struct/structfindvalue.md)
* [StructGet](/boxlang-language/reference/built-in-functions/struct/structget.md)
* [StructGetMetadata](/boxlang-language/reference/built-in-functions/struct/structgetmetadata.md)
* [StructInsert](/boxlang-language/reference/built-in-functions/struct/structinsert.md)
* [StructIsCaseSensitive](/boxlang-language/reference/built-in-functions/struct/structiscasesensitive.md)
* [StructIsOrdered](/boxlang-language/reference/built-in-functions/struct/structisordered.md)
* [StructKeyArray](/boxlang-language/reference/built-in-functions/struct/structkeyarray.md)
* [StructKeyExists](/boxlang-language/reference/built-in-functions/struct/structkeyexists.md)
* [StructKeyList](/boxlang-language/reference/built-in-functions/struct/structkeylist.md)
* [StructKeyTranslate](/boxlang-language/reference/built-in-functions/struct/structkeytranslate.md)
* [StructMap](/boxlang-language/reference/built-in-functions/struct/structmap.md)
* [StructNew](/boxlang-language/reference/built-in-functions/struct/structnew.md)
* [StructNone](/boxlang-language/reference/built-in-functions/struct/structnone.md)
* [StructSome](/boxlang-language/reference/built-in-functions/struct/structsome.md)
* [StructSort](/boxlang-language/reference/built-in-functions/struct/structsort.md)
* [StructToQueryString](/boxlang-language/reference/built-in-functions/struct/structtoquerystring.md)
* [StructToSorted](/boxlang-language/reference/built-in-functions/struct/structtosorted.md)
* [StructUpdate](/boxlang-language/reference/built-in-functions/struct/structupdate.md)
* [StructValueArray](/boxlang-language/reference/built-in-functions/struct/structvaluearray.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structreduce.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
