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?
1 Answer 1
Here you go
var array = JSON.parse(jQuery('#inputId').val());
answered May 16, 2017 at 13:04
schaffioverflow
5103 silver badges14 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
object?JSON.parsethisJSON.parseto convert it to an object