String for unique hash in Javascript / JQuery

Is there a function in Javascript / Jquery that will make a hashtag from a string? I've been looking for an answer for a few minutes now and I can't find it: / Maybe there is another way to do this? I have a Symfony 2.4 application.

I have form data serialized to string like:

"cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictName%5D=Otwartabbb&cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictValue1%5D=fa-comments-o+text-muted&cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictName%5D=Wycena&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictValue1%5D=fa-comments-o+text-muted&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictName%5D=Negocjacje&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictValue1%5D=fa-comments-o+text-muted&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BisDefault%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictName%5D=Wygrana&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictValue1%5D=fa-thumbs-o-up+text-primary&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictName%5D=Przegrana&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictValue1%5D=fa-thumbs-o-down+text-danger&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5B_token%5D=3PBJr_pPjHhAIB95N7PUReP5asrXsGwCILAxZLyGTUg deal:738
cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictName%5D=w%C5%82asnee&cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictName%5D=proklienckii&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictName%5D=telemarketing&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictName%5D=mailing&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictName%5D=www&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B5%5D%5BdictName%5D=partner&cloud_adm_dictionary_type%5Bitems%5D%5B5%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B6%5D%5BdictName%5D=nowe+zrodlo&cloud_adm_dictionary_type%5Bitems%5D%5B6%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B7%5D%5BdictName%5D=Aaa&cloud_adm_dictionary_type%5Bitems%5D%5B7%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5B_token%5D=3PBJr_pPjHhAIB95N7PUReP5asrXsGwCILAxZLyGTUg"

      

And I want to make a hashtag out of this, something like I don't know '462423dfdaak542634'. I need later to compare the hashtags to see if the form has been changed or not.

+3


source to share


1 answer


You can use this simple hashing function here:

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

      



See here DEMO

+5


source







All Articles