Remove Duplicate Numbers in 2D Array Javascript [duplicate]

88
January 10, 2020, at 2:10 PM
This question already has answers here:
Get all unique values in a JavaScript array (remove duplicates) (85 answers)
Merge/flatten an array of arrays (75 answers)
Closed 7 hours ago.

I have a 2D array of number arrays like say

nonunique = [[1,2,3][2,3,4][1,5]];

I want a 1d array of all the unique keywords.

unique = [1,2,3,4,5];

Existing solutions aim at matching the entire arrays rather than just returning a 1d array of numbers. Any shortcuts to this in vanilla javascript?

I tried this reduce function from stackoverflow but it seems to filter some non-duplicate values too.

unique = nonunique.reduce((acc, val) => acc.concat(val.filter((e)=>acc.includes(val))));

It doesn't work properly and I can't figure out how to fix it. I also tried

unique = nonunique.filter(onlyUnique);

but filter(onlyUnique) doesn't seem to be available on firefox.

READ ALSO
WebGL: How can you draw a pentagon?

WebGL: How can you draw a pentagon?

I am practicing WebGL and attempting to draw a pentagon, but I am not sure how to approach thisAny help would be much appreciated

140
How do I do this if statement?

How do I do this if statement?

I am attempting to learn code from scratch and am doing the pre course work for lambda and I have hit a hard brick wall lolI'm a bit older (36) and have no college education and wanted to pursue this for a while but always figured I wasn't smart enough...

119
how to save url created from canvas.toBlob() inside PDFJS.getDocument to array?

how to save url created from canvas.toBlob() inside PDFJS.getDocument to array?

I render the pdf page on canvasThen, I want to save url created from canvas blob to array so that I can access outside of this method

104