how to create GUID formate in javascript


its easy to make guid in javascript. below is code to get strings that look like guid.

example:

function JSGuid() {
  var output, i, j;
  output = '';
  for(j=0; j<32; j++) {
    if( j == 8 || j == 12 || j == 16 || j == 20) 
      output = output + '-';
    i = Math.floor(Math.random()*16).toString(16).toLowerCase();
    output = output + i;
  }
  return output;
}
JSGuid();

note:  it generate hexadecimal digits separated by a hyphen

Post a Comment

0 Comments