2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
title: collections.Intersect
linkTitle: 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.
2019-10-21 04:22:28 -04:00
categories: [functions]
2023-10-20 03:42:39 -04:00
keywords: []
2019-10-21 04:22:28 -04:00
menu:
docs:
2023-05-22 10:43:12 -04:00
parent: functions
2023-10-20 03:42:39 -04:00
function:
aliases: [intersect]
returnType: any
signatures: [collections.Intersect SET1 SET2]
relatedFunctions:
- collections.Complement
- collections.Intersect
- collections.SymDiff
- collections.Union
aliases: [/functions/intersect]
2019-10-21 04:22:28 -04:00
---
2022-11-17 10:14:29 -05:00
A useful example is to use it as `AND` filters when combined with where:
2019-10-21 04:22:28 -04:00
## AND filter in where query
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/