<div class="grid--cell fl1 lh-lg">
<div class="grid--cell fl1 lh-lg">
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, <a href="/help/reopen-questions">visit the help center</a>.
</div>
</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2012-10-10 21:51:44Z" class="relativetime">7 years ago</span>.</div>
</div>
</aside>
How can I convert this json
{
"dates": [
"12-10-2012",
"12-11-2012",
"13-11-2012",
"22-11-2012",
"23-11-2012",
"2-12-2012"
]
}
into an array like this
var array = ["12-10-2012", "12-11-2012", "13-11-2012", "22-11-2012", "23-11-2012", "2-12-2012"]
</div>
What you have is an object that contains the array. All you have to do is get the value of the object using key dates
.
Assuming a var defined for data like below,
var data = {
"dates": [
"12-10-2012",
"12-11-2012",
"13-11-2012",
"22-11-2012",
"23-11-2012",
"2-12-2012"
]
}
then data['dates']
will return you that array.
just use the dates variable itself
var json = { ... your json ...}
var array = json.dates;
the dates property inside your json is an array already
Parse the JSON and get the dates
property:
var array = $.parseJSON(theJsonString).dates;
What you want to do is called parsing. Some browsers, like Chrome have this native function
var obj = JSON.parse(string)
But if you use jQuery, you can use
var obj = $.parseJSON(string)
This will give you an object. You can then do
obj.dates