javascript hash string

/**
 * Calculate a 32 bit FNV-1a hash
 * Found here: https://gist.github.com/vaiorabbit/5657561
 * Ref.: http://isthe.com/chongo/tech/comp/fnv/
 *
 * @param {string} str the input value
 * @param {boolean} [asString=false] set to true to return the hash value as 
 *     8-digit hex string instead of an integer
 * @param {integer} [seed] optionally pass the hash of the previous chunk
 * @returns {integer | string}
 */
function hashFnv32a(str, asString, seed) {
    /*jshint bitwise:false */
    var i, l,
        hval = (seed === undefined) ? 0x811c9dc5 : seed;

    for (i = 0, l = str.length; i < l; i++) {
        hval ^= str.charCodeAt(i);
        hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
    }
    if( asString ){
        // Convert to 8 digit hex string
        return ("0000000" + (hval >>> 0).toString(16)).substr(-8);
    }
    return hval >>> 0;
}

4.33
6
Heinrich 75 points

                                    function hashFnv32a(str, asString, seed) {
    /*jshint bitwise:false */
    var i, l,
        hval = (seed === undefined) ? 0x811c9dc5 : seed;

    for (i = 0, l = str.length; i &lt; l; i++) {
        hval ^= str.charCodeAt(i);
        hval += (hval &lt;&lt; 1) + (hval &lt;&lt; 4) + (hval &lt;&lt; 7) + (hval &lt;&lt; 8) + (hval &lt;&lt; 24);
    }
    if( asString ){
        // Convert to 8 digit hex string
        return (&quot;0000000&quot; + (hval &gt;&gt;&gt; 0).toString(16)).substr(-8);
    }
    return hval &gt;&gt;&gt; 0;
}

4.33 (6 Votes)
0
4
2

                                    function hashCode(str) {
  return str.split('').reduce((prevHash, currVal) =&gt;
    (((prevHash &lt;&lt; 5) - prevHash) + currVal.charCodeAt(0))|0, 0);
}

// Test
console.log(&quot;hashCode(\&quot;Hello!\&quot;): &quot;, hashCode('Hello!'));

4 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
js simple hash get hash of string javascript js simple hash string javascript string hashcode hashing functions javascript what .hash does js js hashing example hash method in javascript node js hash a string hash strings javascript javscript hash javascript browser hash value of hash javascrip[t what is a hash in javascript hash javascript string javascript hash to string javascript get string from hash hash functions in javascript how to hash in js how to use hash in javascript js hash code hash javascript javascript hash a string with a key hash a value to a string in javascript hash in javaScript hash name in javaScript make hash from string javascript simple hash function js how to get hashcode of string javascript how to hash string in node.js how to hash string js js string hash value what is hash in js get hash of string in js this.hash js what does javascript use for hash does javascript have hash hash code in javascript javascript hash tutorial javasceript hash node hash a string hashes javascript built in hash function javascript hash using javascript hashcode string javascript js hash a function string.hashcode() in javascript string.hashcode() in js does javascript have hash method example of a hash function javascript hashing function javascript simple hash js javascript create hash string hash function example js java hash function in javascript js hash-method hashing function for javascript hashing function for javascrip js hash string to hash function for js javascript hashes hash sting js javascript hashm javascript create hash of string hash number javascript this.hash javascript simple hash function in js hash with javascript hash from string javascript what is hash js js string hashcode hash sting in js hash in javascrfipt hash methods javascript how to hash in javascript ._hash javascript javascript get hash of string javascript code hash string hash js what is hash value javascript create javascript hash javascript hash methods .hasher js javascript hash of a string javascript simple hash hashes in javascript javascript hash code hash javascruipt simple javascript hash function hash code js hashing string in javascript js hash values hash to string javascript hash string in javascript how to get hash string from string in javascript how to get hash string the string in javascript how to hash the string in javascript simple hash javascript javascript hash generator from string what is hashing in javascript hash &amp; hash in js hash function js hash() js js string in string hash hash injs javascript hashstring js hash something nodeJS hash a string create simple hash from string javascript what is hash javascript hash in js hashing in js javascript hashing string js hashes.js string hash function javascript javascript hashing hash.js hashing function js hash() javascript how to create a hash from string in js compute hash of a string js javascript hash function html hash js javascript hash functions js hashing function what is a hash javascript js hash function hash string nodejs .hash js hash function javascript nodejs hash string js hash from string js create hash from string generate hash javascript javascript hashing function javascript hash string but not the 3 last js hash string to number javascript hashcode generator js create hash key from arguments convert hash to string js generate a string from hash js convertir le hash en string js change hashed string length js html javascript generate hash generate hash for string javascirpt javascript string gethashcode js hash from number get hash string javascript hash function in javascript javascript make hash from string javascript generate checksum on string javascirtp hash string get hash from text js convert hash to string javascript js get fixed length hash of string js hex string hash code 32 byte string js string hash code js string hash nodejs hash hash code of + in html javascript hashset create hash code in js what is hash table in javascript export hash to string hashCode() javacsript javascript how to hash strings hashing a string in javascript hash in javascript hash a string angular javascript hash function for integers hashing in javascript javascript hash string to hash javascript string to hash hash text javascript javascript string hash Create a JavaScript program to decode hashes as backspaces and return the deleted string. how to make hash in javascript hash string to integer javascript javascript generate hash generate hash string javascript checksum string javascript fast performance generate hash by scrung javascript js hashing string js create a hash hash javascript create create hash from string js inbuilt hash generator js hash of string js .hash js hash a string js hashing vanila js hash string javscript create hash from string to check for changes javscript create hash from string javasctipt create hash from string javascript stringToHash hashing js string tansfomr hash string js hash string js how to hash javascript javascript how to hash a string what is the best way to hash a string in javascript custome hash function in javascript generate hash for string in js hash from string js hash js js hash and shorten string javascript string.hashcode hash text in j how to hash a string in javascript create hash from string javascript hash generator js generate hash js javascript hash text generate hash in javascirpt JAVASCRIPT FIX DIGIT HASH MAKER how to create a hash of a string javascript how to genrate a hash uising javascript javascript hashage text hashing javascript hash a string js type script generate a hash of a string how to create string from hash in javascript how can convert hash to string in javascript hashing string and decode the has string to orginal string in javascript js hash string create hash js hash string javascript typescript hash string js create hash string to hash js generate hash from string js javascript hash string string hashcode javascript javascript hash a string jquqery generate undigest hash hash generator javascript what does hash |= 0 mean in js jquery string hash sha512 how to make my own hashing and dis hashing function in javascript hashing string to integer between 0 to n ts hash a string javascript hashing string to integer small integer js hashing string to integer js js generate hash how to get string back from hash javascript js get hash of string unique hash from string javascript Javascript hash typescript hash string to string typescript create string hash from string typescript create hash from string how to hash your js code hash back a string js how to hash js hash a string in js javascript hash from string javascript create hash from string javascript create hash one line javascript create hash string to hash javascript how to generate hash in javascript typescript create hash based on string javascript js create hash of string js hash different hash javascript js hash java script hash
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source