I've encountered a challenge while working with data received from an API. My goal is to loop through this information and generate HTML elements based on it. The issue lies in the 'subjects' data, which arrives as a string but needs to be manipulated as an array for my purposes.
Here's a glimpse of the sample JSON structure:
{
"employees": [
{
"id": 7099,
"subjects": "English,Biology",
},
...
]
}
Below is a simplified version of the Vue component code I'm currently working with:
<template>
...
</template>
<script>
...
</script>
In a previous scenario, I resolved a similar issue by creating a function to split the strings within 'employee.subjects'. However, this approach won't suffice here since I need to filter the data based on subjects before integrating it into the HTML.
My understanding is that I need to iterate over the JSON, extract the 'subjects', split them, save them into a new array, and then replace the original 'this.employees' with this modified array.
The farthest I've reached so far is shown below:
this.employees.forEach((employee) => {}
I'm feeling stuck on how to proceed. While the task appears straightforward, none of my attempts seem to yield results. Any suggestions or insights would be greatly appreciated.