gpt4 book ai didi

javascript - 使用javascript将数组转换为数组的数组?

转载 作者:行者123 更新时间:2023-12-02 21:25:41 24 4
gpt4 key购买 nike

我想在 Excel 文件上打印一些内容,并且该 Excel 文件适用于数组数组的格式,因此我需要将数组转换为数组数组,如下所示:

['x','y','z'] to [['x'],['y'],['z']] 

我尝试使用 firestore 来存储它并将其推送到数组上

const query = async() => {
const querySnapshot = await db.collection('collectionName').get();
const data = []
querysnapshot.forEach(doc => {
const x = getIdentifier(doc)
data.push(x)
})
console.log(data) //it gives an array like this ['x','y','z']
}
query();

最佳答案

只需使用 map :

const array = ['x','y','z'];
const array2 = array.map(value => [value]);

console.log(array2) // [['x'],['y'],['z']]

关于javascript - 使用javascript将数组转换为数组的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60747226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com