Javascript Array processing If I have an array:

var names = ['John', 'Jim', 'Joe'];


and I want to create a new array from names which afterwards will look like:

newNames = ['John John', 'Jim Jim', 'Joe Joe']


What I came up with is the following:

var newNames = [];
var arr = null;
var loop = 0;

$.each(names, function (i, item) {
  arr = [];
  loop = 2;
  while (loop--) {
    arr.push(item);
  }
  newNames.push(arr.join(' '));
});


Seems like there should be a shorter, easier way to do this. As you can see we can repeat the names with a space n times. I'm experimenting with different ideas/concepts, having fun.
You could use the native Array.map method in modern browsers (see MDN)



const newNames = ['John', 'Jim', 'Joe'].map( name =&gt; `${name} ${name}`);
console.log(newNames);