Created
November 17, 2024 18:56
-
-
Save derockspace/e47abc2fbc4e0c86fdadc8ee5ced3eab to your computer and use it in GitHub Desktop.
This Gist contains a collection of useful JavaScript utility functions that can be reused across different projects. It includes functions for array manipulation, string formatting, and date handling. Feel free to fork this Gist and contribute additional functions or improvements!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Function to format a date to YYYY-MM-DD | |
| function formatDate(date) { | |
| const d = new Date(date); | |
| let month = '' + (d.getMonth() + 1); | |
| let day = '' + d.getDate(); | |
| const year = d.getFullYear(); | |
| if (month.length < 2) month = '0' + month; | |
| if (day.length < 2) day = '0' + day; | |
| return [year, month, day].join('-'); | |
| } | |
| // Function to capitalize the first letter of each word in a string | |
| function capitalizeWords(str) { | |
| return str.replace(/\b\w/g, function(char) { return char.toUpperCase(); }); | |
| } | |
| // Function to find the maximum value in an array | |
| function maxInArray(arr) { | |
| return Math.max(...arr); | |
| } |
Author
Author
Contact: For any questions or contributions, please reach out to me on GitHub or via email at 179988301+derocktools@users.noreply.github.com.
Author
- [https://github.com/DeRock-360)]
2.179988301+derocktools@DeRock.noreply.github.com
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Contact: For any questions or contributions, please reach out to me on GitHub or via email at 179988301+derocktools@users.noreply.github.com.