Iterates over every entry of the Struct and calls the closure function to work on the key value pair of the struct. The returned value will be set for the same key in a new struct and the new struct will be returned.
structMap(struct, function(key, value [,struct]){} [, parallel] [, maxThreads])
→ returns struct
someStruct.map(function(key, value [,struct]){} [, parallel] [, maxThreads])
key
*
string
:
The key for the current iteration
value
*
any
:
The value for the current iteration
struct
*
struct
:
A reference of the original struct
false
true
false
20
original = {
"one": {
1: "tahi"
},
"two": {
2: "rua"
},
"three": {
3: "toru"
},
"four": {
4: "wha"
}
};
function mapOriginal(k,v) {
return v[ListFirst(v.keyList())];
}
fixed = structMap(original,mapOriginal);
writeDump([original, fixed]);
CF 11+ Lucee 4.5+
original = {
"one": {
1: "tahi"
},
"two": {
2: "rua"
},
"three": {
3: "toru"
},
"four": {
4: "wha"
}
};
fixed = original.map(function(k,v) {
return v[ListFirst(v.keyList())];
});
writeDump([original, fixed]);
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.