2

DB JSON column data: ["admin", "leader", "manager"]
javascript recieves: ["admin", "leader", "manager"]

What is the simplest way to create Javascript array?

2
  • 1
    Could you add an example of how you are retreiving the data from the database ? Commented Jan 8, 2020 at 15:10
  • @Nicolas It is Datatable render function: targets: ['roles'], render: function (data, type, row) { datatables.net/reference/option/columns.render Commented Jan 8, 2020 at 15:12

1 Answer 1

2

Just replace "&quot ;" to quotes and parse

const s = "["admin", "leader", "manager"]"
const obj = JSON.parse(s.replace(/"/g, "\"")))

but better check why do you receive data in such format

Sign up to request clarification or add additional context in comments.

2 Comments

It works! Thank you! Appreciate your support! Wish you good year and a lot of profitable projects!
Hahaha, happiness is enough, i dont run for profit.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.