left join two object arrays
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 09:06 PM
I have a question regarding joining two object arrays. I have one object array that contains (for example) ten animals:
data.list = [];
data.list.push({
animal: wf.getDisplayValue('name')
});
and I have another object array that contains the attributes of the only two of the animals:
data.attributes = [];
data.attributes.push({
animal_height: wf.getDisplayValue('height'),
animal_weight: wf.getDisplayValue('weight'),
animal_family: wf.getDisplayValue('family'),
animal_age: wf.getDisplayValue('age')
});
Is there a way for me to left join these two arrays so that ALL ten animals are displayed in a list, along with the attributes associated with the two animals with additional details?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2018 09:24 PM
Hi David,
Are you forced to use that data structure? How do you know which attributes are related to which animal?
Still, leaving that aside, take a look to some of the responses given on this thread: javascript - Merge 2 arrays of objects - Stack Overflow . I believe some of these will be helpful for what you're trying to accomplish.
I hope it helps!
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2018 06:44 AM
Hi bernyalvarado, sorry for the confusion, the second array would have the animal name as well:
data.attributes = [];
data.attributes.push({
animal: wf.getDisplayValue('name'),
animal_height: wf.getDisplayValue('height'),
animal_weight: wf.getDisplayValue('weight'),
animal_family: wf.getDisplayValue('family'),
animal_age: wf.getDisplayValue('age')
});
Also, I'm not forced into this data structure, do you have a cleaner, more efficient way of doing something like this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2018 10:08 PM
Hi David,
If the second array contains the name of the animal, why would you need the first array that only contains the name of the animal?
Thanks,
Berny