Irsyad Nurilhaq
Irsyad Nurilhaq

Reputation: 139

Get value of object in Javascript to array

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

Answers (1)

Nikhil Aggarwal
Nikhil Aggarwal

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

Related Questions