0

I am getting features object and assigning to constants according to their values

const {
  featureCode,
  featureSubType,
  contentId,
  price,
  family: {
    relationCountsConfig: { motherCount, fatherCount, childrenCount },
    maxFamilyMembersCount
  },
  featureWeight
} = feature;

Some time feature.family return {} empty object.

I am getting mother count undefined error.

How do we handle when it's assigning to constants.

keikai
  • 14,085
  • 9
  • 49
  • 68
Sandun Tharaka
  • 727
  • 2
  • 9
  • 29

1 Answers1

0
let feature = {
 featureCode : 'hi',
 featureSubType: 'h',
 contentId: 1,
 price: 1,
 family: {
  relationCountsConfig: { motherCount: 1, fatherCount: 1, childrenCount:1 },
  maxFamilyMembersCount: 10
 },
 featureWeight : 20
}

const {
 featureCode,
 featureSubType,
 contentId,
 price,
 family,
 featureWeight
} = feature;

console.log(family);

Try to spread family object later.

Radu Diță
  • 13,476
  • 2
  • 30
  • 34
Vipin Shukla
  • 235
  • 2
  • 4