0

I'm trying to pass in a reference to one of the declared arrays a,b,c or d depending on the value of element.locationPrimary ( which will always be a,b,c or d). I seem to be passing it in as a string and as a result not able to reference the arrays. I know what I'm doing wrong here but I don't know the terminology to search for an answer or the correct way to do this.

    const a = [];
    const b = [];
    const c = [];
    const d = [];
    records.forEach((element) => {
      **element.locationPrimary**.push([element.locationSecondary, element._id]);
    });

element.locationPrimary.push should push to either a,b,c or d depending on its value

each record has a locationPrimary value of a, b, c or d

I've run into this problem a few times and could really do with an example of the correct way of doing this, I'm very much still getting to grips with JS. I feel it may be a very simple solution however its late and I need to get this sorted before I can sleep soundly tonight!

user3927638
  • 101
  • 2
  • 5

0 Answers0