Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript simple hash

String.prototype.hashCode = function() {
    var hash = 0;
    if (this.length == 0) {
        return hash;
    }
    for (var i = 0; i < this.length; i++) {
        var char = this.charCodeAt(i);
        hash = ((hash<<5)-hash)+char;
        hash = hash & hash; // Convert to 32bit integer
    }
    return hash;
}
Comment

java script hash

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;
}
Comment

How to use hash in javascript

var h = new Object(); // or just {}
h['one'] = 1;
h['two'] = 2;
h['three'] = 3;

// show the values stored
for (var k in h) {
    // use hasOwnProperty to filter out keys from the Object.prototype
    if (h.hasOwnProperty(k)) {
        alert('key is: ' + k + ', value is: ' + h[k]);
    }
}
        
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add two floats 
Javascript :: tofixed javascript 
Javascript :: form contact 7 ajax send 
Javascript :: case insensitive string comparison in javascript 
Javascript :: javascript get currency symbol by currencyCode 
Javascript :: mongodb mapreduce 
Javascript :: networkx get nodes 
Javascript :: looping through json array 
Javascript :: print in javascript 
Javascript :: 10 javascript interview questions 
Javascript :: promise syntax for javascript 
Javascript :: string length javascript 
Javascript :: jquery select element with class 
Javascript :: useLocation for query params 
Javascript :: json to yaml converter 
Javascript :: what does event emitter do in angular 
Javascript :: how to get data from for loop in react native 
Javascript :: sails disable grunt 
Javascript :: js get children last 
Javascript :: round innerhtml value down javascript 
Javascript :: mongoose find in array 
Javascript :: if browser reactjs 
Javascript :: generate svg from javascript 
Javascript :: javascript get the screen color depth 
Javascript :: how to send csrf middleware token in django ajax 
Javascript :: angular hash sign in url 
Javascript :: javascript js ternary operater 
Javascript :: can i select multiple classes and give function to them at once but different in js 
Javascript :: install ejs 
Javascript :: material ui flex direction 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =