We can pass multiple parameters in ES6 using rest parameters, but I would like to know the efficient way to do this in ES5
You can access arguments of a function with arguments object. It returns an object.
function someFn() {
console.log(arguments)
}
someFn(1, 2, 3) // { 0: 1, 1: 2, 2: 3 }
someFn(1, 2) // { 0: 1, 1: 2 }
Peter Scheler
JS enthusiast
function add() { var args = Array.prototype.slice.call(arguments) return args.reduce(function(a, b) { return a + b }) } console.log(add(1, 2)) // 3 console.log(add(1, 2, 3, 4)) // 10See here.