Console Error: Unhandled error during execution of mounted hook Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'split')
It seems to work up until it comes across a group that has no data for continent.
This looks like the issue to me but I'm not sure how to solve it.
Also, I would appreciate a better solution to removing duplicates and trailing commas in all fields of the JSON. Is there a more efficient way to achieve this with just one function?
Any assistance is greatly welcomed
JSON
"response": [
{
"group": {
"continent": "ASIA,EUROPE,ASIA,EUROPE,ASIA,ASIA,EUROPE,EUROPE,ASIA,AUSTRALASIA,AUSTRALASIA,EUROPE,",
"location": "AS,AS,AS,AS,EU,AF,EU,AF,AU,AU,AU,AU,",
},
},
{
"group": {
"continent": "ASIA,EUROPE,AFRICA,EUROPE,ASIA,AFRICA,EUROPE,",
"location": "AS,AS,AS,AU,AU,",
},
},
{
"group": {
"continent": "ASIA,",
},
},
{
"group": {
"continent": "EUROPE,",
},
},
{
"group": {
"continent": "ASIA,EUROPE,",
"location": "AU,AU,"
},
},
....
]
methods: {
removeDuplicates() {
const uniques = [];
this.response.group.continent.split(",").forEach((l) => {
if ( uniques.indexOf(l) == -1 && l !== "") {
uniques.push(l);
}
});
console.log(" uniques : " + uniques);
this.continent = uniques.join(", ");
},
}
mounted() {
this.removeDuplicates();
}