How to disable or add an object to the beginning of arguments in JavaScript

1 answer
  • use .call() instead of .apply() to call unshift()

  • set arguments as the value of this unshift()

  • set 'hello' as an argument to unshift()


 Array.prototype.unshift.call(arguments, 'hello'); 

As @lonesomeday noted, you can use .apply() instead of .call() , but you need to pass an argument like an array as the second argument. So in your case you need to wrap 'hello' in an array.

+14
source

Source: https://habr.com/ru/post/957856/


All Articles