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
  • 164,888
  • 24
  • 203
  • 252
eagercoder
  • 526
  • 1
  • 10
  • 23

0 Answers0