Skip to main content Link Search Menu Expand Document (external link)

in() : Check Value in Collection


On this page

Summary

Check if a value exists in a collection or array. Returns true if the value is found, false otherwise.

Signature

in(value, collection)

Parameters

Parameter Type Required Description
value Any Yes The value to search for
collection Array/Collection Yes The collection to search in

Returns

Type: Boolean

Returns true if the value exists in the collection, false otherwise.


Examples

Simple Membership Check

<p>Has premium: </p>

Data:

doc.Params["model"] = new {
    features = new[] { "basic", "premium", "analytics" }
};

Output:

<p>Has premium: true</p>

Conditional Display Based on Membership


  <p>:
  
    Administrator
  
    User
  
  </p>

Data:

doc.Params["model"] = new {
    adminRoles = new[] { "admin", "superadmin", "moderator" },
    users = new[] {
        new { name = "Alice", role = "admin" },
        new { name = "Bob", role = "user" },
        new { name = "Charlie", role = "moderator" }
    }
};

Output:

<p>Alice: Administrator</p>
<p>Bob: User</p>
<p>Charlie: Administrator</p>

Status Badge Display

<p>Status:

  <span style="color: green;">Active</span>

  <span style="color: orange;">Warning</span>

  <span style="color: red;">Error</span>

</p>

Data:

doc.Params["model"] = new {
    status = "pending",
    activeStatuses = new[] { "active", "running", "ok" },
    warningStatuses = new[] { "pending", "degraded", "slow" }
};

Output:

<p>Status: <span style="color: orange;">Warning</span></p>

Access Control


  
    <p>: Enabled</p>
  

Data:

doc.Params["model"] = new {
    user = new {
        permissions = new[] { "read", "write", "delete" }
    },
    features = new[] {
        new { id = "read", name = "View Data" },
        new { id = "write", name = "Edit Data" },
        new { id = "admin", name = "Admin Panel" }
    }
};

Output:

<p>View Data: Enabled</p>
<p>Edit Data: Enabled</p>

Category Filter

<h3>Priority Items</h3>

  
    <p> ()</p>
  

Data:

doc.Params["model"] = new {
    priorityCategories = new[] { "urgent", "critical", "high" },
    items = new[] {
        new { name = "Bug Fix", category = "urgent" },
        new { name = "Feature Request", category = "low" },
        new { name = "Security Patch", category = "critical" }
    }
};

Output:

<h3>Priority Items</h3>
<p>Bug Fix (urgent)</p>
<p>Security Patch (critical)</p>

Notes

  • Case-sensitive comparison by default
  • Works with arrays and enumerable collections
  • Returns false if collection is null or empty
  • Value comparison uses equality (==)
  • Useful for:
    • Role-based access checks
    • Feature flag evaluation
    • Status filtering
    • Whitelist/blacklist checks
    • Category membership
  • Performance: O(n) linear search through collection
  • For string containment within a single string, use contains() instead
  • Can check numeric values, strings, or any comparable type
  • Does not support wildcard or pattern matching

See Also