Skip to content
Related Articles

Related Articles

Improve Article

HTML DOM indexedDB cmp() Method

  • Last Updated : 19 Jul, 2020

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:

  • 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.




<!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:

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

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :