0

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"]
2
  • Why do you need that array just to show in dropdown and not iterate original? Commented Jun 9, 2018 at 15:43
  • I want to get data from database and then disable specific date datepicker Commented Jun 9, 2018 at 15:49

1 Answer 1

3

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);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.