2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
title: collections.Intersect
2021-03-21 08:31:17 -04:00
description: Returns the common elements of two arrays or slices, in the same order as the first array.
2023-12-04 09:14:18 -05:00
categories: []
2023-10-20 03:42:39 -04:00
keywords: []
2023-12-04 09:14:18 -05:00
action:
2023-10-20 03:42:39 -04:00
aliases: [intersect]
2023-12-04 09:14:18 -05:00
related:
- functions/collections/Complement
- functions/collections/SymDiff
- functions/collections/Union
2023-10-20 03:42:39 -04:00
returnType: any
signatures: [collections.Intersect SET1 SET2]
aliases: [/functions/intersect]
2019-10-21 04:22:28 -04:00
---
2023-12-04 09:14:18 -05:00
A useful example is to use it as `AND` filters when combined with where:
2019-10-21 04:22:28 -04:00
2023-05-22 10:43:12 -04:00
```go-html-template
2019-10-21 04:22:28 -04:00
{{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
{{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }}
{{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }}
```
2023-07-29 05:15:54 -04:00
The above fetches regular pages not of `page` or `about` type unless they are pinned. And finally, we exclude all pages with no `images` set in Page parameters.
2019-10-21 04:22:28 -04:00
2023-10-20 03:42:39 -04:00
See [union ](/functions/collections/union ) for `OR` .
2019-10-21 04:22:28 -04:00
[partials]: /templates/partials/
[single]: /templates/single-page-templates/