cooper
cooper

Reputation: 437

How to convert a string to an array in javascript?

I have an input on a form which stores values as an object.

jQuery('#inputId').val()

returns something like

'[{"Id":"123","Name":"A","PathOfTerm":"A","Children":[],"Level":0,"RawTerm":null},{"Id":"234","Name":"B","PathOfTerm":"B","Children":[],"Level":0,"RawTerm":null}]'

as one single string. Is there any way to either prevent this from automatically converting to a string (maybe not using .val?) or to convert this from a string to something I could work with?

Upvotes: 0

Views: 118

Answers (1)

schaffioverflow
schaffioverflow

Reputation: 510

Here you go

var array = JSON.parse(jQuery('#inputId').val());

Upvotes: 5

Related Questions