I get a text below this from the database which has multiple strings with double quotes like the one below,
["Time Usage: 9.00am – 4.00pm",
"Rental of Commune Room 01 (7 Hours)",
"55" Smart TV, 1x Clear Writing Glass, Marker Pen, HDMI Cable, Complimentary WiFi, and Filtered Water"]
Expect Output to Customer
- Time Usage: 9.00am – 4.00pm
- Rental of Commune Room 01 (7 Hours)
- 55" Smart TV, 1x Clear Writing Glass, Marker Pen, HDMI Cable, Complimentary WiFi and Filtered Water
Current Output I get from below code
- Time Usage: 9.00am – 4.00pm,Rental of Commune Room 01 (7 Hours),55" Smart TV
- 1x Clear Writing Glass
- Marker Pen
- HDMI Cable
- Complimentary WiFi
- and Filtered Water
I used the below code,
let description = (["Time Usage: 9.00am - 4.00pm",
"Rental of Commune Room 01 (7 Hours)",
"55" Smart TV, 1x Clear Writing Glass, Marker Pen, HDMI Cable, Complimentary WiFi, and Filtered Water"]
)
description = description.toString()
description = description.replace(/(rn|n|r)/gm, '')
if (description !== '') {
description = description.replace(/^/, '* ')
description = description.replace(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/gm, '|')
}
description = description.split('|')
description = description.join('n * ')
console.log(description);
Can someone helps me to fixed this?
2
Answers
You don’t need that fancy code, because
description
is array (if it’s string, dolet description = JSON.parse(description)
):Please note that with jQuery ajax it would be much faster/less code:
You can try something but i prefer above answers.