javascript - how to use jquery .append() in a JS FOR loop? -
this question has answer here:
ok have function
success: function (data) { $('#chat').val(data); (var = 0, < data.length, i++) { $.append("#id: " + "#mesaage"); } }
in data variable holds json array displayed this:
{id: message}
how can give format print "id: message" without curly brackets?
you can make use of object.keys
here:
success: function (data) { var key = object.keys(data) $('#chat').val(key +":"+ data[key]); },
a sample test below:
var data = {"id":"message"}; var key = object.keys(data); $(document.body).append(key +":"+ data[key]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Comments
Post a Comment