I have two separate arrays of data I need to merge into a single array where the values of keys match. I am creating the two arrays via the functions below as the data comes from two separate areas, but should be related.
Example of desired merge by ID:
array1 = [{"name": "bob", "id":"1"}, {"name": "sue", "id":"2"}]
array2 = [{"location": "vegas", "id":"1"}, {"location": "texas", "id":"2"}]
desiredarray = [{"name": "bob", "id":"1", "location": "vegas"}, {"name": "sue", "id":"2", "location": "texas", }]
Here is my current code that creates the two arrays:
$scope.termsArray = [];
$scope.labelsArray = [];
execOperation();
function execOperation() {
//Current Context
var context = SP.ClientContext.get_current();
//Current Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
//Term Stores
var termStores = taxSession.get_termStores();
//Name of the Term Store from which to get the Terms.
var termStore = termStores.getByName("Taxonomy1111");
//GUID of Term Set from which to get the Terms.
var termSet = termStore.getTermSet("1111");
var terms = termSet.getAllTerms();
context.load(terms);
context.executeQueryAsync(function () {
var termEnumerator = terms.getEnumerator();
//var termList = "Terms: \n";
while (termEnumerator.moveNext()) {
var currentTerm = termEnumerator.get_current();
var guid = currentTerm.get_id();
var guidString = guid.toString();
$scope.termsArray.push({
termName: currentTerm.get_name(),
termGUID: guidString,
termSynonyms: 'Coming Soon'
});
getLabels(guid);
//termList += currentTerm.get_id() + currentTerm.get_name() + "\n";
}
//alert(termList);
}, function (sender, args) {
console.log(args.get_message());
});
}
function getLabels(termguid) {
var clientContext = SP.ClientContext.get_current();
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(clientContext );
var termStores = taxSession.get_termStores();
var termStore = termStores.getByName("Taxonomy1111");
var termSet = termStore.getTermSet("1111");//change the term set guid here
var term = termSet.getTerm(termguid);
var labelColl = term.getAllLabels(1033);
clientContext.load(labelColl);
clientContext.executeQueryAsync(function () {
var labelEnumerator = labelColl.getEnumerator();
while (labelEnumerator.moveNext()) {
var label = labelEnumerator.get_current();
var value = label.get_value();
// array push function where value is passed?
$scope.labelsArray.push({
termLabel: value,
termGUID: termguid
});;
}
}, function (sender, args) {
console.log(args.get_message());
});
}