I want to remove double quote from only data node from json string.
current json:
[{"name":"Labor Shortage Index","data":["0.2","0.5","0.5","1.8"]}]
So after remove double quote json will be:
[{"name":"Labor Shortage Index","data":[0.2,0.5,0.5,1.8]}]
Please suggest.
Thanks
With applying Number
for every element.
var object = [{ "name": "Labor Shortage Index", "data": ["0.2", "0.5", "0.5", "1.8"] }]; object[0].data = object[0].data.map(Number); document.write('<pre>' + JSON.stringify(object, 0, 4) + '</pre>');
data
arrayparseFloat
on ittry this code
var obj = [{"name":"Labor Shortage Index","data":["0.2","0.5","0.5","1.8"]}];
obj = obj.map(function(value){
value.data = value.data.map(function(innerValue){ return parseFloat(innerValue); });
return value;
});
One answer would be to use an array map to parse the data node array:
var parsedData = data.map(function(num){ return parseFloat(num); });
See array map and parseFloat .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.