Wednesday, August 26, 2015

How to (implode) join array elements with a string?

<script>
var testArr = [{"id":9,"name":"Test 0"},{"id":5,"name":"Test 1"},{"id":6,"name":"Test 2"}];

var str = testArr.map(function(elem){
  return elem.name;
}).join(", ");

console.log(str);
</script>

No comments: