Open In App

HTML DOM indexedDB cmp() Method

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

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

Parameters:



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

Returned value Description
-1 Key 1 < Key 2
0 Key 1 = Key 2
1 Key 1 > Key 2

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




<!DOCTYPE HTML> 
<html>  
<head>
    <title>indexedDB cmp() method</title>
</head>   
<body style="text-align:center;">
    <h1 style="color:green;">  
        GeeksforGeeks  
    </h1
    <p
    HTML | indexedDB cmp() method
    </p>
    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
    </button>
    <p id="a"
    </p>       
    <script
        var a = document.getElementById("a");
        function Geeks() {
            var fir = 
             document.getElementById("fir").value;
            var sec = 
             document.getElementById("sec").value;
            var result = window.indexedDB.cmp(fir, sec);
            if(result==0){
                a.innerHTML = "Both are equal";
            }
            else if(result==1){
                a.innerHTML = "a is greater";
            }
            else{
                a.innerHTML = "b is greater";
            }
          
        
    </script
</body>   
</html>

Output:
Before Button Click:



After Button Click:

Supported Browsers:


Article Tags :