Convert Char array to String - Node.js String

Node.js examples for String:Char

Description

Convert Char array to String

Demo Code

Array.prototype.charArr2Str = function() {
  // We can just do str.split(""), 
  // but that won't check that only characters were passed in.
  var str = '', elem, error = false;
  for(var i = 0; i < this.length; i++ ) {
    elem = this[ i ].toString();/*from   ww  w .j  a  va 2 s  .co  m*/
    if( elem.length <= 1 ) {
      str += elem;
    } else {
      throw 'Value ' + elem + " can't be converted to a character.";
    }
  }
  return str;
}

Related Tutorials