Hi I need to convert this:
// Convert [[1],[2],[3],[4],["a","b","c"],["d","e","f"]]
to this:
[1,2,3,4,"a","b","c","d","e","f"]
In MS Office Script. I can't use
I've tried using things like array.flat(), but it doesn't exist in Office Script.
Hi I need to convert this:
// Convert [[1],[2],[3],[4],["a","b","c"],["d","e","f"]]
to this:
[1,2,3,4,"a","b","c","d","e","f"]
In MS Office Script. I can't use
I've tried using things like array.flat(), but it doesn't exist in Office Script.
Normal
On
const givenArray = [[1], [2], [3], [4], ["a", "b", "c"], ["d", "e", "f"]]
function flattenArray(arr) {
return arr.reduce((result, el) => {
return result.concat(Array.isArray(el) ? flattenArray(el) : el)
}, [])
}
const givenArrayFlattened = flattenArray(givenArray)
console.log(givenArrayFlattened)
Copyright © 2021 Jogjafile Inc.
Try something like that may be it's help