Generate a simple numeric hash from a string.
Code
Utilitieslet hash = 0;
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) - hash) + str.charCodeAt(i);
hash |= 0;
}
return Math.abs(hash).toString();Parameters
String to hash.
Browser·fetch() may be limited by CORS
More JavaScript Snippets
Constant Time Compare
Compare two strings in constant time to prevent timing attacks. Unlike === which returns early on first mismatch, this compares all characters regardless of where differences occur.
FNV-1a Hash
Fast non-cryptographic hash function.
Generate Password
Generate a cryptographically secure random password with configurable options.
Hash SHA-256
Generate a SHA-256 hash of a string. SHA-256 produces a fixed 64-character hexadecimal output regardless of input size.
Parse JWT Payload
Extract and decode the payload from a JWT token without verification. Useful for reading claims like user ID, expiration time, and roles from tokens.
XSS Attack Prevention
Escape HTML entities to prevent Cross-Site Scripting attacks.