Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

28 December 2021

How to Remove Value from Array using Jquery


<!DOCTYPE html>
<html>
  <head>
    <script src="js/jquery-3.6.0.js"></script>
    <script>
      $(document).ready(function () {
        var arrNumber = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12];
        var removeValue = 2;
        arrNumber = $.grep(arrNumber, function (n) {
          return n != removeValue;
        });
        alert(arrNumber);
      });
    </script>
  </head>
  <body></body>
</html>

 

Github Link: https://github.com/adi501/JQuery-Examples




How to Check if Value Exists In Array or Not using Jquery


<!DOCTYPE html>
<html>
  <head>
    <script src="js/jquery-3.6.0.js"></script>
    <script>
      $(document).ready(function () {
        var arrStu = ["adi", "pavan", "madhan", "yagnesh"];
        if ($.inArray("adi", arrStu) >= 0) {
         alert("Value exists");
        } else {
            alert("Value Not exists");
        }
      });
    </script>
  </head>
  <body></body>
</html>

Github Link: https://github.com/adi501/JQuery-Examples