Skip to content
Related Articles
Open in App
Not now

Related Articles

HTML DOM indexedDB cmp() Method

Improve Article
Save Article
Like Article
  • Last Updated : 19 Jul, 2020
Improve Article
Save Article
Like Article

The indexedDB cmp() method is used to compare two values as keys to determine equality and ordering for further IndexedDB operations.

var result = indexedDB.cmp(key1, key2);


  • key1: The first key to compare.
  • key2: The second key to compare.

Return value: It returns an integer that indicates the result of the comparison.

Returned valueDescription
-1Key 1 < Key 2
0Key 1 = Key 2
1Key 1 > Key 2

Example: In this example, we will compare two keys using this method.

    <title>indexedDB cmp() method</title>
<body style="text-align:center;">
    <h1 style="color:green;">  
    HTML | indexedDB cmp() method
    Enter First Number : 
      <input type="number" id="fir"><br><br>
    Enter Second Number :  
      <input type="number" id="sec"><br><br>
    <button onclick = "Geeks()">
    Click to Compare
    <p id="a"
        var a = document.getElementById("a");
        function Geeks() {
            var fir = 
            var sec = 
            var result = window.indexedDB.cmp(fir, sec);
                a.innerHTML = "Both are equal";
            else if(result==1){
                a.innerHTML = "a is greater";
                a.innerHTML = "b is greater";

Before Button Click:

After Button Click:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer (Partial Support)

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!