Javascript Data Type How to - Split each letter and use space as separator








Question

We would like to know how to split each letter and use space as separator.

Answer


<!DOCTYPE html>
<html>
<body>
<script type='text/javascript'>
<!-- w  ww .  ja  va  2 s . com-->
function sStr(aString)
{   
    return aString.split("").join(" ");
}
document.writeln(sStr('hello'));

</script>
</body>
</html>

The code above is rendered as follows: