# collections.Apply
> 用指定的函数及参数逐个转换给定切片的元素，返回新切片。
- 官方英文原文：https://gohugo.io/functions/collections/apply/
- 本页规范地址：https://hugozh.cn/functions/collections/apply/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：collections.Apply SLICE FUNCTION PARAM...
- 返回类型：[]any
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
`apply` 函数接收三个或更多参数，具体数量取决于要应用到切片元素上的函数。

第一个参数是切片本身，第二个参数是函数名，其余参数会传给该函数，其中字符串 `"."` 代表切片元素。

```go-html-template
{{ $s := slice "hello" "world" }}

{{ $s = apply $s "strings.FirstUpper" "." }}
{{ $s }} → [Hello World]

{{ $s = apply $s "strings.Replace" "." "l" "_" }}
{{ $s }} →  [He__o Wor_d]
```

