I'm currently working on converting a string to a JavaScript object. I've been using the JSON.parse method successfully, but I've encountered an issue when trying to delete items from the object - it seems to be missing or not deleting the commas. Here is the code snippet and its output:
var jsonString = '[{"connectionName" : "conn1", "ipaddress" : "127.0.0.1","port" : "80"}, {"connectionName" : "conn2", "ipaddress" : "127.0.0.100","port" : "760"}]';
var a = JSON.parse(jsonString);
delete a[1];
var obj = {"connectionName" : "conn3", "ipaddress" : "127.0.0.100","port" : "760"};
a.push(obj);
console.dir(a);
Output:
[ { connectionName: 'conn1', ipaddress: '127.0.0.1', port: '80' },
,
{ connectionName: 'conn3',
ipaddress: '127.0.0.100',
port: '760' } ]
If you notice, there is an extra comma between two objects:
'80' },
,
{ connectionName: