Title: Populate select option with JSON Object element
Tags: javascript;html
Question: I want to populate a select tag with options contained in a JSON Object :
Hi need to populate this select :
<select class="selectpicker" name="iroleinspecteurcommercial" id="iroleinspecteurcommercial" data-live-search="true" data-actions-box="true" multiple&gt;</select&gt;</br&gt;
with informations from arr1.libellerole
I tried this code but no results :
$.each(arr1.libellerole, function(k, v){
$("#iselectroledirregional").append('<option&gt;'+v+'</option&gt;');
});
Thank you

Here is the accepted answer: Based on the image you've provided, there is no arr1.libellerole. Instead, you have to iterate over every element in the array and access its libellerole property.
Also, the id of the <select&gt; you've given and the one in your JavaScript code don't match.
Try this:
$.each(arr1, function (k, v) {
$("#iroleinspecteurcommercial").append('<option&gt;' + v.libellerole + '</option&gt;');
Example:
var arr1 = [
{libellerole: 1},
{libellerole: 2},
{libellerole: 3},
{libellerole: 4},
{libellerole: 5}
$.each(arr1, function(k, v) {
$("#iroleinspecteurcommercial").append('<option&gt;' + v.libellerole + '</option&gt;');
<script src = "//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;</script&gt;
<select id = "iroleinspecteurcommercial" multiple&gt;</select&gt;


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:04/27/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><html>', 'Title': 'Populate select option with JSON Object element', 'ViewCount': 216, 'id': 61457700, 'user_AboutMe': None, 'user_AccountId': 14516749.0, 'user_DisplayName': 'userHG', 'user_Reputation': 557.0, 'user_Views': 151.0, 'user_id': 10485625.0}}