When accessing my website from google chrome everything works fine(also on mobile). but when trying to access from edge \ mobile normal browser(not google chrome) i get
TypeError: Object doesn't support property or method 'flat'
trying to access a function .flat of array.
turns out that it dosent exist on the proto at all. what can i do with it? the childs array is defined as
`let childs = [];`
(using react for front end)
You use the flat() method for concatenating sub-arrays recursively into a single array. The flat() method takes a depth value as its parameter which is optional depending on the depth of the array you wish to flatten (concatenate). The flat() method takes in 1 as a depth by default.
The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
The flatMap() method returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level.
IE does not support Array.prototype.flat()
. you can use reduce
and concat
as a workaround:
childs = childs.reduce((acc, val) => acc.concat(val), [])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With