I have a data entry page that is used to collect data for an HTTP PUT request. One of the ion-select options provides some name values to choose from. I need to get the ID’s from that array that match the users selected names for the PUT request; and not sure how to go about doing this. I found something similar here: comparing two arrays, they are trying to find the differences between the arrays in this example. Also, they are not using Angular/Ionic 2. Is there a simple way to do this in Angular/Ionic 2 that I’ve overlooked?.. Appreciate any guidance.
Asked
Active
Viewed 1,016 times
0
-
1I think the way you refered above is very simple and no need to find another way. Angular and Ionic do not have any built in function to do it. – Duannx Aug 14 '17 at 02:26
-
you need to make a function or method to do that. simple filter or map out the indexes. and some conditions will do what you need. – Jakegarbo Aug 14 '17 at 07:34
-
Ok, Thanks Duannx and Jake. I'll move forward with this approach. – ob1 Aug 14 '17 at 14:50
-
I tried something referenced in this post: [link](https://stackoverflow.com/questions/1723168/what-is-the-fastest-or-most-elegant-way-to-compute-a-set-difference-using-javasc) It works, but the problem is it only returns the same NAME. I need to get the ID from the "allchoices" array too, which is not included in the "selected" array. Wondering if there is a way to just add the ID to HTML as a hidden field or something? .. This is example of what is just returning name: `results = this.selected.filter(e=> this.allchoices.indexOf(e) < 0);` – ob1 Aug 14 '17 at 21:01
-
**UPDATE** I tried below, but it returns everything from "allchoices" array which is basically everything. Please let me know if you have any suggestions. `var getID = function (obj) { return _.pick(obj, 'id', 'name'); } this.results = _.merge(this.selected, _.map(this.allchoices, getID));` – ob1 Aug 15 '17 at 00:27
-
I tried some additional things referenced here [link](https://stackoverflow.com/questions/34795049/merge-property-from-an-array-of-objects-into-another-based-on-property-value-lod), but they don't work in Angular/Ionic 2: – ob1 Aug 15 '17 at 00:28