I have a json data like this.
data = [{"value": "One", "value2": "1"}, {"value": "Two", "value2": "2"}, {"value": "Three", "value2": "3"}, {"value": "Four", "value2": "4"}]
I want to create dropdown with label of value
and data-value of value2
.
I'm able to create a dropdown by passing any one single column to a array like this.
chart_data = []; data.forEach(function(d) { chart_data.push(d.value) }) ["one","two","three"] // result
With that result I create a dropdown using jquery's $.each()
function.
$.each(chart_data, function(i, val) { $('#dropdown').append('' + val + ''); })
But over there I'm able to create using only single column.
I'm looking to create a dropdown from two column values with 1 col for the label and other for the data-value.