[ Deleting Particular Parts of a JSON ]
Was hoping someone may be able to point me in the right direction with this.
I have returned a list object in JSON format from .Net and then parse with JQuery.
var jsonOpens = $g.parseJSON(seriesReturn);
If I alert this I then receive the following:
1326531600000,8,49,1326531600000,8,49,1326535200000,11,169,1326535200000,11,169
What I then need to do with this is remove the second column.
I managed to do that by looping through and deleting
for (var i = 0; i < jsonOpens.length; i++) {
delete jsonOpens[i] [1];
}
This works but still leaves the column in place i.e alerts:
1326531600000,,49,1326531600000,,49,1326535200000,,169,1326535200000,,169
I tried doing a replace by replacing the double commas with single commas but this doesn't work in this format.
What would be the best way for me to identify a column and remove it completey whilst keeping the same format?
Answer 1
Assuming it's a JS array, you should be able to use the .splice() method to remove the appropriate elements:
http://www.w3schools.com/jsref/jsref_splice.asp
So, your loop would be (I think)
for (var i = 0; i < jsonOpens.length; i++) {
jsonOpens[i].splice(1,1);
}