Currently, I am facing a challenge in attempting to flatten a Uint8ClampedArray
.
The initial array structure is data = [227, 138, 255…]
and after creating an array from that like
enc = [Uint8ClampedArray[900], Uint8ClampedArray[900], Uint8ClampedArray[900]...]
, my goal is to flatten it.
I have tried various methods and solutions, including:
the method suggested by MDN
var flattened = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {
return a.concat(b);
}, []);
using concat
data = [].concat.apply([], enc);
and utilizing a function
function flatten(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
However, none of these approaches have been successful so far. The array keeps returning in its original form. Can anyone provide guidance on the right approach and explain why this is happening?
-EDIT- In essence, I need it to be converted into a regular Array object, similar to the starting one without a specified type.