Apologies for the simplicity of my query.
I am in the process of streamlining some code and have been exploring the use of array.map rather than traditional for loops to iterate through arrays and using array.push. I've managed to grasp the fundamentals, but I'm facing difficulties when trying to add a conditional statement. Here is my current code snippet:
var masterArray = [{
"masterName": "One",
"minorArray": []
},
{
"masterName": "Two",
"minorArray": ["A", "B", "C"]
},
{
"masterName": "Three",
"minorArray": ["Q", "W", "E", "R", "T", "Y"]
},
{
"masterName": "Four",
"minorArray": [1, 2, 3, 4, 5]
},
];
var minorArray = [];
var setMinorArray = function(value) {
var selectedName = value;
for (var i = 0; i < masterArray.length; i++) {
if (masterArray[i].masterName == selectedName) {
minorArray = [];
minorArray = masterArray[i].minorArray;
break;
}
}
console.log(minorArray);
};
setMinorArray("Three");
Since I need compatibility with IE11 users, I am unable to utilize arrow functions. Any guidance on this would be greatly appreciated.
Thank you so much