Stack Overflow Asked by Pyarel on December 23, 2021
I have data coming from api where one of the attribute has value like,
[{
......
attr_name: "["abcd"]"
attr_names:"{abcd}"
.......
}]
How do i convert this value to array ["abcd"] ?
Thank you in advance.
Try with JSON.parse
which will convert json string
to object
.
Loop over data
array and convert it and assign back it itself as below.
data.forEach(d => d.attr_name = JSON.parse(d.attr_name));
let data = [{
attr_name: '["abcd"]',
attr_names: "{abcd}"
}];
data.forEach(d => d.attr_name = JSON.parse(d.attr_name));
console.log(data);
Answered by Karan on December 23, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP