I
I
Igor Fedorov2016-09-18 09:32:53
JavaScript
Igor Fedorov, 2016-09-18 09:32:53

How to write only received keys from Json?

Hello everyone, the server returns the following result in json:

response: { 
messages: 6 
}


And there is a list, with data-attributes, for example

<p data-name="messages"></p>
<p data-name="friends"></p>
<p data-name="gifts"></p>


How to run the response in Jquery/js and write only the existing keys in the html tag code? That is, the server may not return all existing ones

. That is, the messages in the response correspond to data-name="messages" and so on.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2016-09-18
@igor-fedorov

You can get the keys of an object using
For(var key in obj){.... console.log(key);}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question