• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

131
Views
what is comma trailing in javascript
const army = {
     name: 'karan',
     memb : [
            {
                captain: 'suraj',
            },
            {
                rifleMan: 'sanjay'
            },
            {
                grenadier: 'yogesh'
            }
      ]
}
    
const { name , memb:[, cap]} = army
    
console.log("cap ", cap)

This gives cap { rifleMan: 'sanjay' }.

Can anyone please explain this concept and what it is called

about 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You are de-structuring the army object. So "karen" is stored in name and from the army.memb which is an array you want the second element and store it in cap.

For example if you put two commas it means you want the third element of the memb array:

const army = {
  name: 'karan',
  memb: [{
      captain: 'suraj',
    },
    {
      rifleMan: 'sanjay'
    },
    {
      grenadier: 'yogesh'
    }
  ]
}

const { name, memb: [,, cap]} = army


console.log("cap ", cap)

about 3 years ago · Juan Pablo Isaza Report

0

It is feature of array destructuring in javascript. It is used to ignore or skip certain values while destructuring.

const [a, , b] = [1, 2, 3];
console.log(a,b);   // 1,3
const [, a, b] = [1, 2, 3];
console.log(a,b);   // 2,3
about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error