Wednesday, 7 June 2023

Most Important JavaScript Methods || JavaScript Practice

 JavaScript Methods 

 

             1. Remove all whitespace from a string:

             Ans:-

            var stringWithoutWhitespace = string.replace(/\s/g, '');

           2. Convert a string to an integer:

           Ans:-

            var integer = parseInt(string);

            3. Sort an array in ascending order:

             Ans:-

            array.sort(function(a, b) {
              return a - b;
            });

            4. Find the maximum value in an array:

            Ans:-

            var max = Math.max(...array);

            5. Find the minimum value in an array:

            Ans:-

            var min = Math.min(...array);


                                  Thanks for visiting



No comments:

Post a Comment

This is me