I pass from php to js object. For example :
{"3199":{"name":"Ramona RONDEREGGER","mail":"mona.schlaepfer@bluewin.ch","phone":null,"hope":null
,"status":"NEW LEAD"},"3253":{"name":"Olivia
BAUMANN","mail":"oliviazurfluh@gmail.com","phone":null,"hope"
:null,"status":"NEW LEAD"}}
And I want to get data from this object in js (get 3199, 3253 and their data (name,mail ...). How can I do it? I try it:
$(data).each(function(key,value){
$(value).each(function(key,value){
console.log(value);
});
});
But id doesn't work Please, help me to solve this problem Thanks
Specify key like this value["3199"]
var data = {"3199":{"name":"Ramona RONDEREGGER","mail":"mona.schlaepfer@bluewin.ch","phone":null,"hope":null,"status":"NEW LEAD"},"3253":{"name":"Olivia BAUMANN","mail":"oliviazurfluh@gmail.com","phone":null,"hope"
:null,"status":"NEW LEAD"}};
$(data).each(function(key,value){
$(value).each(function(key,value){
console.log(value["3199"]);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</div>
Iterate through your object and get data by key. Here is the example of your dataset showed that how can you access the data in your result object.
var data = {"3199":{"name":"Ramona RONDEREGGER","mail":"mona.schlaepfer@bluewin.ch","phone":null,"hope":null
,"status":"NEW LEAD"},
"3253":{"name":"Olivia BAUMANN","mail":"oliviazurfluh@gmail.com","phone":null,"hope"
:null,"status":"NEW LEAD"}};
for(x in data){
// this will print your key
console.log("this is your key " + x);
// this line will print your key object
console.log(data[x]);
//to access internal element
console.log(data[x]['mail']);
}
</div>