Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i want to convert a string like "00000000-0000-0000-0000-000000000000" into guid
is it possible in javascript
Posted
Updated 15-May-20 20:57pm

function create_UUID(){
    var dt = new Date().getTime();
    var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = (dt + Math.random()*16)%16 | 0;
        dt = Math.floor(dt/16);
        return (c=='x' ? r :(r&0x3|0x8)).toString(16);
    });
    return uuid;
}

console.log(create_UUID());
 
Share this answer
 
Comments
Richard Deeming 18-May-20 12:21pm    
How is a function to create a new Guid supposed to be a solution to a question about converting an existing string to a Guid?
SQL
I don't think javascript has guid type. In javascript, guid is just string type.
So you need not convert string to guid.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900