0

I have a string as shown below

[{ date: new Date(2015,9,25), NAV: 12},{ date: new Date(2016,9,25), NAV: 22}]

how can i convert that to object array using jQuery?

Quicksilver
  • 2,546
  • 3
  • 23
  • 37
Ajai
  • 11
  • 1
  • 3

4 Answers4

4

Since new Date(2015,9,25) is not valid JSON, than you need to use eval(yourString) to parse your string to valid Object:

console.log(eval('[{ date: new Date(2015,9,25), NAV: 12},{ date: new Date(2016,9,25), NAV: 22}]'));
Justinas
  • 41,402
  • 5
  • 66
  • 96
1

You can convert to a valid Javascript object using function

JSON.parse(str);

but string should be in valid json format.

kailash yogeshwar
  • 836
  • 1
  • 9
  • 26
0

try this,

var obj = $.parseJSON(jsonString);

or 

var obj = jQuery.parseJSON(jsonString);

may be this might help

Rehan Shikkalgar
  • 1,029
  • 8
  • 16
0

you can convert it to json.parse:

    var json = $.parseJSON(myString)

or you can refer this link below

Safely turning a JSON string into an object

Community
  • 1
  • 1