+ 1

Is it possible to print all the arguments that passed ?

Like const printAllParam= (a, b, c...) => { // code } printAllParam(1, 5, 6,....)

23rd Jun 2023, 3:18 AM
Hariharan
Hariharan - avatar
5 Respostas
+ 4
Yes you can use the destructuring operator '...' for that function printAllParams(...args){ console.log(args) }
23rd Jun 2023, 5:22 AM
Virtual Pixel || good bits
Virtual Pixel || good bits - avatar
+ 3
You can use it with arrow function and you can also use it to extract properties from objects aswell example: let user = { name : "John", email : "john@example.com", age: 20, job: "Software Engineer", address: "Mumbai" } // extract name, email, and put all other things in other let {name,email,...other} = user; console.log(name,email) console.log(JSON.stringify(other))
23rd Jun 2023, 5:35 AM
Virtual Pixel || good bits
Virtual Pixel || good bits - avatar
+ 3
Yes it's possible : function printAll(...nums) { for (let num of nums) { document.write(num) } } printAll(1,2,4,7); printAll(6,4,9);
23rd Jun 2023, 2:49 PM
Sherief Ismail
Sherief Ismail - avatar
+ 2
Virtual Pixel Thankyou! , it is not possible in arrow function na?
23rd Jun 2023, 5:34 AM
Hariharan
Hariharan - avatar
+ 2
Virtual Pixel okay Got it! arrow function don't have 𝙖𝙧𝙜𝙪𝙢𝙚𝙣𝙩 object but using spread operator we can achieve it
23rd Jun 2023, 5:43 AM
Hariharan
Hariharan - avatar