I am trying to split strings I input by commas (.split(',')) but I have ran into an issue with my strings.
Sometimes, the strings I'm provided have commas that are part of a single name. For example: "John, Smith".
My strings usually look like this: "Emily, Sasha Flora, Camille-O'neal" etc which results in 3 objects as I need but sometimes I'm provided with a string like "Emily, Sasha Flora, Camille-O'neal, John, Smith" and the result is that I get are 5 objects when it's actually 4. How can I make the code work with provided strings that contains commas and still get the result I need?
My code in case is this:
var myValue = ["Emily, Sasha Flora, John, Smith, Camille-O'neal"]
var names = myValue.split(',').map(item => ({ name: item.trim() }));
I've tried getting help from ChatGPT but it didn't help.
I'm expecting to get the results like so:
Emily
Sasha Flora
John, Smith
Camille-O'neal