Skip to content

Javascript parse a string with commas

I am getting this string from my api call: I need to find a way to parse it and be able to iterate over the items in attachments list, but when I try to run JSON.parse(str) I am getting an error, I guess because the word attachments has commas around it. The error is Uncaught SyntaxError: Unexpected token &#8…

How to remove repeated code for ternary operator?

I’m receiving the data where a lot of fields are null, and I have to populate something if the field is null. like in the below data As here, the transit_depart is null, I’m using the ternary operator to put something in return if the data is null like this ; This is working as expected but the pr…