Simplifying the array of objects with comma separated values Looking a way to reduce the below code to get comma separated values from the list of arrays
By using ECMA or plain old vanilla JS. How should we achieve this?
Actual Array Data:
[{
    ansBook: &quot;046H&quot;,
    ansPersonId: &quot;2044000102&quot;,
    bookNbr: &quot;046H&quot;,
    dns: &quot;0&quot;,
    examCode: &quot;20717010&quot;,
    examShortTitle: &quot;QA-ATAG-Director of Applications&quot;,
    nar: &quot;0&quot;,
    personId: &quot;2044000102&quot;,
    pull: &quot;0&quot;,
    wn: &quot;0&quot;,
    corrCd: 1
  },
  {
    ansBook: &quot;046I&quot;,
    ansPersonId: &quot;2044000102&quot;,
    bookNbr: &quot;046I&quot;,
    dns: &quot;0&quot;,
    examCode: &quot;20721010&quot;,
    examShortTitle: &quot;QA-ATAG-Plans Examinier&quot;,
    nar: &quot;0&quot;,
    personId: &quot;2044000102&quot;,
    pull: &quot;0&quot;,
    wn: &quot;0&quot;,
    corrCd: 1
  }
];

Expected Result:
{
  &quot;PersonIds&quot;: &quot;2044000102, 2044000102&quot;,
  &quot;BookLetCodes&quot;: &quot;046H, 046I&quot;,
  &quot;ExamNumbers&quot;: &quot;20717010, 20721010&quot;,
  &quot;ExamTitles&quot;: &quot;QA-ATAG-Director of Applications, QA-ATAG-Plans Examinier&quot;
}

As I am getting the expected result. But I need to reduce and improvise the performance performed on it..


let seriesDataSet = [{
    ansBook: "046H",
    ansPersonId: "2044000102",
    bookNbr: "046H",
    dns: "0",
    examCode: "20717010",
    examShortTitle: "QA-ATAG-Director of Applications",
    nar: "0",
    personId: "2044000102",
    pull: "0",
    wn: "0",
    corrCd: 1
  },
  {
    ansBook: "046I",
    ansPersonId: "2044000102",
    bookNbr: "046I",
    dns: "0",
    examCode: "20721010",
    examShortTitle: "QA-ATAG-Plans Examinier",
    nar: "0",
    personId: "2044000102",
    pull: "0",
    wn: "0",
    corrCd: 1
  }
];

let auditingInfo = {};
auditingInfo = (seriesDataSet).filter(w =&gt; (w.dns == '0' &amp;&amp; w.pull == '0') &amp;&amp; w.corrCd == 1)
  .map(e =&gt; ({
    PersonIds: e.personId,
    BookLetCodes: e.ansBook,
    ExamNumbers: e.examCode,
    ExamTitles: e.examShortTitle
  }))
console.log(auditingInfo)

let auditingDetails = {
  PersonIds: auditingInfo.map(x =&gt; x.PersonIds).join(', '),
  BookLetCodes: auditingInfo.map(x =&gt; x.BookLetCodes).join(', '),
  ExamNumbers: auditingInfo.map(x =&gt; x.ExamNumbers).join(', '),
  ExamTitles: auditingInfo.map(x =&gt; x.ExamTitles).join(', ')
}
console.log('______________________________________________')
console.log('Expected Result:')
console.log(auditingDetails)
.as-console-wrapper {
  max-height: 100% !important;
  top: 0;
}



OR
let ScoringApprove: Array&lt;number&gt; = [];
ScoringApprove = new List&lt;SeriesReportsDataset&gt;(this.tempSeriesDataSet)
                .Where(w =&gt; (w.dns == '0' &amp;&amp; w.pull == '0') &amp;&amp; w.corrCd == 1)
                .Select(s =&gt; s.scannedResponseID).ToArray();
Honestly, structure-wise, your code seems pretty good. I've just got a handful of minor code-cleanup suggestions:

Use === instead of ==, == does some magical type coercion, and can create unexpected results.
You've got some unenesary parentheses here: auditingInfo = (seriesDataSet).filter(w =&gt; (w.dns === '0' &amp;&amp; w.pull === '0') &amp;&amp; w.corrCd === 1) - you can take out the parentheses around (seriesDataSet) and (w.dns === '0' &amp;&amp; w.pull === '0')
What's the reason for initializing auditingInfo to {}, then immediately setting it to a different value? Just do it in one go. For example:

// instead of
let auditingInfo = {};
auditingInfo = ...
// just do
let auditingInfo = ...;

You're using a .map() to extract and rename values from your data set, then the next thing you do is some .map()s again to extract out specific values. Why not take out the first .map() entirely?
After applying these suggestions, you'll be left with this:
let auditingInfo = seriesDataSet.filter(w =&gt; w.dns === &quot;0&quot; &amp;&amp; w.pull === &quot;0&quot; &amp;&amp; w.corrCd === 1);

let auditingDetails = {
  PersonIds: auditingInfo.map(x =&gt; x.personId).join(&quot;, &quot;),
  BookLetCodes: auditingInfo.map(x =&gt; x.ansBook).join(&quot;, &quot;),
  ExamNumbers: auditingInfo.map(x =&gt; x.examCode).join(&quot;, &quot;),
  ExamTitles: auditingInfo.map(x =&gt; x.examShortTitle).join(&quot;, &quot;)
};

Finally, you had also asked about improving performance. You're not doing anything slow algorithm-wise, so there's not a whole lot of performance gains you can squeeze out of this. I wouldn't bother unless you really need it, in which case, you can try out different micro-optimizations and run performance tests on your target platforms to see which optimizations help the most. (some optimizations could speed things up on one platform and slow them down on another). Any of these types of optimizations will reduce the readability of your code, so only apply them if they make a significant enough impact.
A couple of optimization ideas you can try out that may help out, or may make things worse:

Use a single for loop instead of using .filter() and multiple .map() calls.
Instead of array.join(), gradually build the string.
If you have a large dataset, see if you can gradually consume a stream of data, instead of loading the whole thing into memory, all at once.