Javascript join example by separator

<!DOCTYPE html>
<html>
<head>

</head>
<body>

<button onclick="arrayjoin()">Click to convert array to string by join</button>
<p id="p1"></p>
<script type="text/javascript">
function arrayjoin(){
var USStates = ["New York", "Texas", "Florida","Alaska"];

Strarr = USStates.join(" | ");
document.getElementById("p1").innerHTML = Strarr; 
} 
</script>
</body>
</html>

  

posted @ 2015-06-14 10:42  hephec  阅读(171)  评论(0编辑  收藏  举报