I am writing an API in a Node.js application. This is a POST call that sends a bunch of data and along with it, it sends the timings
parameter in the body as a string that looks like an array [["11:00 AM", "1:00 PM"], ["1:00 PM", "4:00 PM"]]
. When I am inserting it into MongoDB, it is getting stored as an array but with the entire text as a string in the first array element.
I know I can circumvent this by asking the client application to send a comma-separated string like 11:00 AM,1:00 PM and split the string in JavaScript before inserting it into the database using String.split()
but that only works for single-dimension arrays. I have a multi-dimensional array that is being sent as a string in the POST request. How do I convert it to an array?