concat, but prepend instead of append

Viewed 2396

I have this situation:

const args = ['b','c','d'];
var foo = 'a';
args.unshift(foo);
fn.apply(ctx, args); // args => ['a','b','c','d'] ✅

I could use concat, but that would put foo at the end of the list:

const args = ['b','c','d'];
var foo = 'a';
fn.apply(ctx, args.concat(foo)); // args => ['b','c','d','a'] ❌

I am looking for "precat", so that I can create a new array with the new element at the front, what's the best way to do this with JS? I am open to anything that saves me a line of code :)

2 Answers
Related