Skip to content

Instantly share code, notes, and snippets.

@tripdog
Last active June 12, 2021 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripdog/8eb05f0ffb1c37c879f4ada84bdec553 to your computer and use it in GitHub Desktop.
Save tripdog/8eb05f0ffb1c37c879f4ada84bdec553 to your computer and use it in GitHub Desktop.
Access a Function's arguments as an Array

Function Arguments As An Array:

/*The 'arguments' of a function can be accessed with the arguments keyword. */

function sortedArgs() {
  console.log(Array.isArray(arguments));
  //false
  
  // to create an array from the arguments
  // use the Array.from() prototype method
  // `arguments` is a pseudo-array
  let argList =Array.from(arguments)
  console.log(Array.isArray(argList))
  //true
  return argList.sort()
}
console.log(sortedArgs(3, 1, 2)
//False
//True
//[ 1, 2, 3 ] *credit to <enki/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment