30 seconds of code

  Back to Home

nthArg

utilityfunctionbeginner

Creates a function that gets the argument at index n. If n is negative, the nth argument from the end is returned.

Use Array.prototype.slice() to get the desired argument at index n.

const nthArg = n => (...args) => args.slice(n)[0];