CKTIS / JavaScript
DOMStringList and membership checks with contains()
DOMStringList is a list of strings exposed by some Web APIs that you do not modify directly. Its contains() method checks whether a supplied string belongs to the list and returns a boolean. A typical use is checking object store names in IndexedDB.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
list.contains(string)DOMStringList is a legacy Web API interface representing a list of strings. You receive it from another API rather than creating it with new DOMStringList(). One example is IDBDatabase.objectStoreNames, the list of object store names in an IndexedDB database. The interface being legacy does not mean that APIs returning it are deprecated.
DOMStringList.contains, called as list.contains(string), returns true when the supplied string is in the list, or false when it is absent. The argument is required: calling list.contains() without an argument throws TypeError.
This is not an ordinary JavaScript array. Its length property is read-only, and the interface provides no mutation methods such as push() or splice(). Changes are made through the API that owns the data, not through the list itself.
In the IndexedDB path, the example creates a separate database with a notes store, checks whether two names are present, and logs both results to the console: true for notes and false for missing. DOMStringList is a browser-environment API, not a feature of a particular ECMAScript edition. MDN marks the interface and contains() as widely available since July 2015; having Node 24 in a repository does not establish support for these APIs.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DOMStringList membership</title>
</head>
<body>
<script>
(() => {
function checkMembership(list, present) {
console.log(list.contains(present));
console.log(list.contains('missing'));
}
function useAncestorOrigins() {
// Chromium also exposes a DOMStringList through Location.ancestorOrigins.
// A local child document has at least one ancestor without using storage.
const frame = document.createElement('iframe');
frame.hidden = true;
frame.title = 'DOMStringList test fixture';
frame.srcdoc = '<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Local fixture</title></head><body></body></html>';
frame.addEventListener('load', () => {
const list = frame.contentWindow.location.ancestorOrigins;
if (list?.length) {
checkMembership(list, list.item(0));
} else {
console.warn('Skipping membership checks: IndexedDB could not be opened and Location.ancestorOrigins is unavailable or empty.');
}
frame.remove();
}, { once: true });
document.body.append(frame);
}
const name = `cktis-list-${Date.now()}-${Math.random()}`;
let open;
try {
open = indexedDB.open(name, 1);
} catch {
useAncestorOrigins();
return;
}
open.onerror = useAncestorOrigins;
open.onupgradeneeded = () => open.result.createObjectStore('notes');
open.onsuccess = () => {
const db = open.result;
checkMembership(db.objectStoreNames, 'notes');
db.close();
indexedDB.deleteDatabase(name);
};
})();
</script>
</body>
</html>Result
true false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.