2

The idea is to remove duplicate id's upon selection of records using checkbox. Below is the code used.

selectedTaskObj3 = [];
let el = this.template.querySelector("lightning-datatable");
let selectedRowsArray = el.getSelectedRows();
//**note**: until here I get the output as an object array
let selectedTaskObjChecktest = JSON.stringify(selectedRowsArray).map((item)=>item.Id)
this.selectedTaskObj3 = Array.from(new Set(selectedTaskObjChecktest));

However it is working perfect in console log but not on the page which is totally strange.

The output from the console log

4
  • 4
    You JSON.stringify the data, thus making a "string", so the map function would fail.
    – sfdcfox
    Sep 7, 2020 at 16:11
  • Also, you're not even using JSON.stringify in the console. You have your objArray object, which you then call map on. What happens in your code above when you call selectedRowsArray.map?
    – pchittum
    Sep 7, 2020 at 16:16
  • Oh okay, it throws me a script error Sep 7, 2020 at 16:21
  • @sfdcfox Thanks for your response . I got it now. Removed the JSON.stringify now and tried. For some reason I did not try to use directly without stringyfying. Now it works perfect. Sep 7, 2020 at 16:32

1 Answer 1

4

You do not JSON.stringify an Array before attempting to use Array methods, such as Array.prototype.map.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .