# Check if an array is a subset of another array

Return true when every value of subset appears in of.

Canonical: https://1loc.dev/validator/check-if-an-array-is-subset-of-other-array/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function isSubset({ subset, of }) { const all = new Set(of); return subset.every(value => all.has(value)); }
```

## Input

```json
{
  "subset": [
    "ana@example.com"
  ],
  "of": [
    "ana@example.com",
    "rui@example.com"
  ]
}
```

## Expected output

```json
true
```

## Edge case

Input:
```json
{
  "subset": [
    "lia@example.com"
  ],
  "of": []
}
```
Output:
```json
false
```

## Limits

- The original comment said “b is a subset of a” while its code tested the opposite, and its second variant compared joined strings. Named fields remove the ambiguity.
- Values compare with SameValueZero; objects by reference.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/check-if-an-array-is-subset-of-other-array.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: lupu60
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Rewritten with named fields; the original comment contradicted its code and its second variant compared joined strings. Original MDX retained as inert source evidence.
