I would like to generate cases in a switch statement from an array. Here is how the array is generated:
pointObjects = [];
for (var i = 0; i < 2; i++) {
// Generate cases.
var url;
var pointObject =
{
case: 'Placeholder',
url: 'google.com'
}
pointObjects.push(pointObject);
}
Thus, pointObjects[0] returns:
{
case: 'Placeholder'
url: 'google.com
}
I’d like to render these each within a switch statement, so it will act the same as the code below:
click: function(event) {
var seriesName = this.name;
var url;
// Attaches the query link to the respective slice.
switch (seriesName) {
case 'Placeholder':
url = 'google.com';
break;
case 'Placeholder':
url = 'google.com';
break;
default:
url = '#';
}
// Opens the query in a new tab
if (url !== '#') {
window.open(url, '_blank');
}
}
I tried the following code but it says that pointObjects is an unexpected identifier:
switch (seriesName) {
pointObjects.forEach(obj => {
case obj.case:
url = obj.url;
break;
});
default:
url = '#';
}