I have javascript objects like:
{["186,2017"]}
I would like to only have:
186, 2017
I tried (thougth i had a json):
console.log(JSON.stringify(data));
But that is what gives me the json and not the string values only,
This is how I get the whoel thing:
$("#years").slider({
tooltip: 'always',
tooltip_position:'left',
formatter: function(value) {
currentRange = value instanceof Array ? value.join('-'): value;
return 'Years: ' + (value instanceof Array ? value.join('-'): value);
console.log(value instanceof Array ? value.join(', '): value);
}
});
getData = function() {
var data = {
years: $('#years').slider().val().split(', ')
}
console.log(JSON.stringify(data));
}
$("#years").on("slide", function(slideEvt) {
getData();
});
{["186,2017"]}is not valid JSON - if the JSON is["186,2017"]...JSON.parse(json).map(Number)- though, that would result in[186,2017]... because you still have an array ... so, perhaps ...JSON.parse(json).join(", ")- in the above , json is the JSON string that "you have" ... if what you have is an array,data.. then you just wantdata.join(', '){years: ["186", "2017"]}