+ 1
Is it possible to print all the arguments that passed ?
Like const printAllParam= (a, b, c...) => { // code } printAllParam(1, 5, 6,....)
5 odpowiedzi
+ 4
Yes you can use the destructuring operator '...' for that
function printAllParams(...args){
console.log(args)
}
+ 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))
+ 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);
+ 2
Virtual Pixel Thankyou! , it is not possible in arrow function na?
+ 2
Virtual Pixel okay Got it!
arrow function don't have 𝙖𝙧𝙜𝙪𝙢𝙚𝙣𝙩 object but using spread operator we can achieve it