MS Office 脚本中的数组转换

问题描述 投票:0回答:1

嗨,我需要转换这个:

// Convert [[1],[2],[3],[4],["a","b","c"],["d","e","f"]] 

对此:

[1,2,3,4,"a","b","c","d","e","f"]

在 MS Office 脚本中。我无法使用

我尝试过使用 array.flat() 之类的东西,但它在 Office Script API 中不存在。

感谢任何帮助,我是 Office 脚本新手!

javascript typescript office-scripts ms-office-script
1个回答
0
投票

你可以试试

Array::reduce()
:

const result = [[1],[2],[3],[4],["a","b","c"],["d","e","f"]].reduce((r, item) => (item.forEach(x => r.push(x)), r), []);
console.log(...result);

© www.soinside.com 2019 - 2024. All rights reserved.