Javascript Convert String to Object(list/array)

Problem 1: Can this be achieved in javascript?

value = "['iPhone', 'iBall']" 

to

value = ['iPhone', 'iBall']

Problem 2:
To make it harder, The values are encoded:

value = "['iPhone', 'iball']"

2 thoughts on “Javascript Convert String to Object(list/array)”

  1. Does this help ?

    var value = "['iPhone', 'iBall']";
    value = value.replaceAll(`'`, `"`);
    console.log(JSON.parse(value));
    
    
    value = "['iPhone', 'iball']";
    value = value.replaceAll(`'`, `"`);
    console.log(JSON.parse(value));
    Reply

Leave a Comment