我有以下地圖:
let mapObject = new Map();
mapObject.set("one", "file1");
mapObject.set("two", "file2");
mapObject.set("three", "file3");
console.log([...mapObject.entries()]);
并且控制臺生成以下輸出:
[ [ 'one', 'file1' ], [ 'two', 'file2' ], [ 'three', 'file3' ] ]
我從這篇文章中得到了這個想法,但是如果您在控制臺陳述句中添加字串,則此解決方案不起作用:
console.log("This is a map: " [...mapObject.entries()]);
它會生成以下輸出:
This is a map: one,file1,two,file2,three,file3
這對閱讀不太友好。我想知道如何獲得相同的輸出:console.log([...mapObject.entries()])但是為了通用目的能夠將它存盤在一個字串中。有沒有一種簡單的方法可以實作它適用于谷歌應用程式腳本?
uj5u.com熱心網友回復:
您可以使用JSON.stringify:
let mapObject = new Map();
mapObject.set("one", "file1");
mapObject.set("two", "file2");
mapObject.set("three", "file3");
const res = JSON.stringify([...mapObject.entries()])
console.log("This is a map: " res);
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/351005.html
