0

I have a list like this as ko.observableArray([])

enter image description here

And I just need to have all ID fields inside it

I coded this but I ran into some errors

 self.ApprovePersonAttendanceDataList().ID()

and

 self.ApprovePersonAttendanceDataList()['ID']

And I tried below code but I got ab empty array

self.ApprovePersonAttendanceDataList().map(x => x.ID)
  • 1
    `self.ApprovePersonAttendanceDataList().map(x => x.ID)` – VLAZ Jul 10 '21 at 06:44
  • 1
    Does this answer your question? [From an array of objects, extract value of a property as array](https://stackoverflow.com/questions/19590865/from-an-array-of-objects-extract-value-of-a-property-as-array) – VLAZ Jul 10 '21 at 06:44
  • @VLAZ I think so ,maybe there are two ways,map and pluck function would help but I don't know the difference –  Jul 10 '21 at 06:47
  • `pluck` is also an option, if you have Underscore: `_.pluck(self.ApprovePersonAttendanceDataList(), "ID")`. You can also use `_.map` as `_.map(self.ApprovePersonAttendanceDataList(), "ID")` would do the same. – VLAZ Jul 10 '21 at 06:50
  • 1
    This link http://www.knockmeout.net/2011/04/utility-functions-in-knockoutjs.html could help. You could use `ko.utils.arrayMap()`. – Jose Luis Jul 10 '21 at 09:30

1 Answers1

0

but this one worked! don't know exactly why.

self.ApprovePersonAttendanceDataList().map(({ ID }) => ID))