I am trying to return a custom json object from a javascript function, my code is below
Fiddle
html
<input type='checkbox' name='chk[]' value='1'>1 <input type='checkbox' name='chk[]' value='2'>2 <input type='text' id='txt' value='' /> <input id='btn' type='button' value='click' />
Js
var json = {}; $('#btn').click(function(){ console.log(getdata()); }); function getdata(){ $('input:checked').each(function(i){ json.chk = $(this).val();
I need a result like below
{ chk: [{val: 1}, {val: 2}], txt: 'test' };
source share