Hello I have one lightning component where I have questions and answers from two different objects which are related master-detail. I have built a javascript map to hold Selected radio button value and parent question id. It works well but in one scenario it breaks.

Two questions have same Radio options for example:

Question 1 Yes No

Question 2

Yes No

Question 3

Not Good Good

When i select different values for each Question 1 and Question 2, it works well but when i select same values for question 1 and question 2 it removes the other value and shows only one value.

For example:

If i select Yes for Question 1 and No for Question 2 it holds both values but If i select either yes for both questions or No for both questions, it holds only one value and removes the other value. enter image description here

enter image description here

1 Answer 1


Map is a collection of elements where each element is stored as a Key, Value pair. If the key is repeated, it will override the existing element with the updated one.

As you are holding the answers as Key in the Map, and if the answer is repeated, it will override the existing value in the Map. This is the reason, you are getting only two values when you are selecting the same answers. So, this is working as per design.

You can change the Map structure to hold QuestionId (which I suppose from the screenshot would be unique) as the Key and Answer as the value, that should solve your problem.

  • Thanks Vijay It helped! Apr 9, 2019 at 6:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .