jQuery Data Type How to - Concatenate string array in JavaScript - with modification while concatenating








Question

We would like to know how to concatenate string array in JavaScript - with modification while concatenating.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.1.0.js'></script>
<script type='text/javascript'>
document.writeln(["X", "Y"].map(function(n){ return "{label:" + n + "}" }).join(","));
</script><!--from  w  w  w .j a v a 2s  .  c o  m-->
</head>
<body>
</body>
</html>

The code above is rendered as follows: