0

I'm familiar with the spread operator documentation examples on MDNenter link description here, and think they are very clear about copying an arrays values into a new variable:

var parts = ['shoulders', 'knees']; 
var lyrics = ['head', ...parts, 'and', 'toes']; 
// ["head", "shoulders", "knees", "and", "toes"]

I want to know if I could apply the same principle to the following hash table, by only defining one variable:

const hashTable = {
  base: ['yieldToWorst', 'coupon', 'maturityDate'],
  muni: [...base, 'quantity', 'states'],
  corp: [...base, 'price'],
}

In this case base will not be defined when I attempted to use the spread operator, so I attempted the following:

const hashTable = {
  base: ['yieldToWorst', 'coupon', 'maturityDate'],
  muni: [hashTable['base'], 'quantity', 'states'],
  corp: [hashTable['base'], 'price'],
}

but this issue is that hasTable is not yet defined. Any solution to this, while containing all the code in one variable?

Praveen Kumar Purushothaman
  • 160,666
  • 24
  • 190
  • 242
eagercoder
  • 360
  • 7
  • 22

0 Answers0