mvn.2047
mvn.2047

Reputation: 362

How to convert mySQL JSON column into javascript array?

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

What is the simplest way to create Javascript array?

Upvotes: 2

Views: 427

Answers (1)

Dmitry Reutov
Dmitry Reutov

Reputation: 3032

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

Upvotes: 2

Related Questions