endsWith() : Check String Suffix
On this page
Summary
Check if a string ends with a specified suffix.
Signature
endsWith(str, suffix)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
str |
String | Yes | The string to check |
suffix |
String | Yes | The suffix to look for |
Returns
Type: Boolean
true if the string ends with the suffix, false otherwise.
Examples
File Extension Check
Data:
doc.Params["model"] = new {
files = new[] {
new { name = "document.pdf" },
new { name = "photo.jpg" },
new { name = "report.docx" }
}
};
Output:
<div class="file-pdf">
<span class="icon">📄</span> document.pdf
</div>
<div class="file-image">
<span class="icon">🖼️</span> photo.jpg
</div>
Domain Validation
Data:
doc.Params["model"] = new {
email = "john.doe@company.com"
};
Output:
<span class="badge-internal">Internal</span>
URL Path Checking
Version Suffix
Data:
doc.Params["model"] = new {
products = new[] {
new { name = "Product A", version = "1.0.0" },
new { name = "Product B", version = "2.0.0-beta" },
new { name = "Product C", version = "3.0.0-alpha" }
}
};
Output:
<div class="product">
<h3>Product A</h3>
<span class="badge-stable">Stable</span>
</div>
<div class="product">
<h3>Product B</h3>
<span class="badge-beta">Beta</span>
</div>
<div class="product">
<h3>Product C</h3>
<span class="badge-alpha">Alpha</span>
</div>
Notes
- Case-sensitive by default
- Returns false if suffix is not found at end
- Empty suffix returns true
- For case-insensitive check, use with
toLower():endsWith(toLower(str), toLower(suffix)) - For prefix checking, use
startsWith() - For substring anywhere, use
contains()