set.map()
Description
The map()
method creates a Set by applying the functionBody
to each value in the Set, and returns the new Set. The source
set isn’t changed.
If map()
is the last value in a query, the first page of the new
Set is returned.
Writes are not permitted by functionBody.
Iterator methods
FQL provides several methods for iterating over a set.
set.forEach()
and
set.map()
are similar but used for
different purposes:
Method | Primary use | Notes |
---|---|---|
Perform in-place writes on set elements. |
Doesn’t return a value. |
|
Return a new set with projected or transformed elements. |
Can’t perform writes. |
|
Similar to |
Can’t perform writes. |
Examples
For all Customer documents, combine the address.city
and address.state
properties into a single string:
Customer.all().map(
customer => "#{customer.address.city}, #{customer.address.state}"
)
{
data: [
"Washington, DC",
"Washington, DC",
"Washington, DC"
]
}
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!