Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
Multiple args in javascript function

How can I pass more than one arg in a function without knowing the number of args that I will need to pass?

function uniteUnique(arr) {
(do somthing here)
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);

what I mean is the func above receive one arg, but the function is called with 3 arg this time, but in other exercise is called with 4 arg.

The best solution in my case was using arguments

function uniteUnique( ){
console.log(arguments)
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
// logs { '0': [ 1, 3, 2 ], '1': [ 5, 2, 1, 4 ], '2': [ 2, 1 ] }
// i can work with this
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is the way to go if you use typescript/ ES6

function uniteUnique(...arrays) {
(do somthing here)
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);

where arrays mean variable number of arrays ( could be 2 or 3 or whatever )

or for old javascript / ES5 :

function uniteUnique() {
    (do somthing here , with usage of **`arguments`** object)
    }
    
    uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!