Reputation: 139
I want show data in select drop down with jquery ajax. This my code :
$(document).ready(function() {
$(".inventaris").on('change',function(e) {
console.log(e);
var cat_id = e.target.value;
$.get('/get-id/' + cat_id , function(data){
$.each(data, function(index, obj){
console.log(obj);
});
});
});
});
The result is :
[{id: 1, tgl_pinjam: "2018-06-10"},{id: 2, tgl_pinjam: "2018-06-11"}]
How to get?
["2018-06-10","2018-06-11"]
Upvotes: 0
Views: 30
Reputation: 28445
Use Array.map
let arr = [{id: 1, tgl_pinjam: "2018-06-10"},{id: 2, tgl_pinjam: "2018-06-11"}];
let result = arr.map(({tgl_pinjam}) => tgl_pinjam);
console.log(result);
Upvotes: 3