--- title: IDBKeyRange.includes() slug: Web/API/IDBKeyRange/includes tags: - API - IDBKeyRange - IndexedDB - Méthode - Reference translation_of: Web/API/IDBKeyRange/includes ---
La méthode includes()
, rattachée à l'interface {{domxref("IDBKeyRange")}}, renvoie un booléen si la clé est contenue dans un intervalle de clé.
{{AvailableInWorkers}}
myIncludesResult = myKeyRange.includes('A');
key
Un booléen.
Cette méthode peut lever une exception {{domxref("DOMException")}} de type {{domxref("DataError")}} lorsque la clé fournie n'est pas une clé valide.
var keyRangeValue = IDBKeyRange.bound('A', 'K', false, false); var monResultat = keyRangeValue.includes('F'); // Renvoie true var monResultat = keyRangeValue.includes('W'); // Renvoie false
Spécification | État | Commentaires |
---|---|---|
{{SpecName('IndexedDB 2', '#dom-idbkeyrange-includes', 'includes()')}} | {{Spec2('IndexedDB')}} |
Fonctionnalité | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Support simple |
{{CompatChrome(52.0)}} |
{{CompatGeckoDesktop("47.0")}} | {{CompatUnknown}} | {{CompatOpera(39)}} | {{CompatUnknown}} |
Fonctionnalité | Android | Webview Android | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile | Chrome pour Android |
---|---|---|---|---|---|---|---|---|
Support simple | {{CompatNo}} | {{CompatChrome(52.0)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatOperaMobile(39)}} | {{CompatUnknown}} | {{CompatChrome(52.0)}} |
La méhode includes()
a été ajoutée à partir de la deuxième édition de la spécification d'Indexed DB. Pour les navigateurs qui ne prennent pas en charge cette fonctionnalité, on peut utiliser la prothèse suivante.
IDBKeyRange.prototype.includes = IDBKeyRange.prototype.includes || function(key) { var r = this, c; if (r.lower !== undefined) { c = indexedDB.cmp(key, r.lower); if (r.lowerOpen && c <= 0) return false; if (!r.lowerOpen && c < 0) return false; } if (r.upper !== undefined) { c = indexedDB.cmp(key, r.upper); if (r.upperOpen && c >= 0) return false; if (!r.upperOpen && c > 0) return false; } return true; };