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 :: delete element from array js 
Javascript :: js max array 
Javascript :: make canvas cover whole screen in html 
Javascript :: how to check electron verion 
Javascript :: break in if statement js 
Javascript :: node.js brotli 
Javascript :: add getter to object javascript 
Javascript :: function is not defined in jquery 
Javascript :: javascript create form element 
Javascript :: timestamp to date 
Javascript :: how to add a variable in js 
Javascript :: get current date javascript full month 
Javascript :: ticking clock react js 
Javascript :: importing svg into cra 
Javascript :: javascript return first match in array 
Javascript :: js ignore case 
Javascript :: js get the filename you uploaded 
Javascript :: distinguishing positive numbers in javascript 
Javascript :: extract the last number of two digits number js 
Javascript :: javascript data 
Javascript :: javascript last character of a string 
Javascript :: Using vuejs-datepicker with Nuxt JS 
Javascript :: kendo grid toolbar custom button click event jquery 
Javascript :: cloudwatch logs sdk. 
Javascript :: momentjs get calendar week 
Javascript :: array.push 
Javascript :: javascript map function 
Javascript :: import an image react in the public folder 
Javascript :: mysql json 
Javascript :: Create JavaScript Strings 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =