{
"clientIds": [{
"id": 0,
"clientId": "check123"
}]
}
The above is json object. How to split this into key value? I got key is: clientIds but value comes object I want check123 value and append in dropdown using jquery how to divide and append in dropdown.
You can access the clientId
and Id
as
var a = {"clientIds":[{"id":0,"clientId":"check123"}]};
alert(a.clientIds[0].clientId);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</div>
To take the object and turn it into options in a select menu do the following.
for(var i = 0; i < clientIds.length; i++){
$('#dropdown').append($('<option />').val(clientIds[i].id)).text(clientIds[i].clientId));
}
Since clientIds
is an array, iterate over it.
var data = {"clientIds":[{"id":0,"clientId":"check123"}]};
$.each(data, function(index, element) {
var id = element.id; // will have the value 0
var clientId = element.clientId; // will have the value check123
});
Once you got these, build your dropdown.
var a = {"clientIds":[{"id":0,"clientId":"check123"}]};
$.each( a.clientIds,function () {
$('#dropdown').append($('<option />').val($(this).id)).text($(this).clientId);
});
Try this:
var a = {"clientIds":[{"id":0,"clientId":"check123"}]};
for(i=0;i<a.clientIds.length;i++)
$('#myoptions').append($('<option value="'+a.clientIds[i].id+'">'+a.clientIds[i].clientId+'</option>'));