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

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -