const names = ['john', 'smith', 'karl']; const get = (arr, str) => arr.map(v=>str?`${str} ${v}`:v) console.log(get(names, 'Mr')) console.log(get(names))