我需要以下JS結構(結果從請求承諾查詢)的JavaScript轉換對象的陣列中的陣列2D
[ { idfactura: 2,
idcuenta: 1,
nombre: 'Nick',
periodo: 'Per1 ',
formapago: 'Tarj ',
cantidadpersonas: 1,
subtotal: 7000,
porcentajedescuento: 0,
fecha: '24/11/2017 02:38' },
{ idfactura: 3,
idcuenta: 1,
nombre: 'Adm',
periodo: 'Per1 ',
formapago: 'Efec ',
cantidadpersonas: 1,
subtotal: 7000,
porcentajedescuento: 10,
fecha: '25/11/2017 23:45' } ]
爲了確切以下結構(在XLSX導出):
[[2, 1, 'Nick', 'Per1', 'Tarj', 1, 7000, 0, '24/11/2017 02:38'],
[3, 1, 'Adm', 'Per1', 'Efec', 1, 7000, 10, '25/11/2017 23:45']]
我試過_
方法,值,JSON.stringify作爲其他帖子在Stackoverflow,但我無法得到我確切的輸出結構。
例如代碼:
results = [ { idfactura: 2,
idcuenta: 1,
nombre: 'Nick',
periodo: 'Per1 ',
formapago: 'Tarj ',
cantidadpersonas: 1,
subtotal: 7000,
porcentajedescuento: 0,
fecha: '24/11/2017 02:38' },
{ idfactura: 3,
idcuenta: 1,
nombre: 'Adm',
periodo: 'Per1 ',
formapago: 'Efec ',
cantidadpersonas: 1,
subtotal: 7000,
porcentajedescuento: 10,
fecha: '25/11/2017 23:45' } ]
var arr = Object.key(results).map(function(key){
return [results[key]];
});
您的片段並不在我的linux的NodeJS終端執行(--version的NodeJS v4.8.2):'''常量mappedResults = ... results.map(結果= (key)> ... Object.keys(result).map(key => ..... typeof(result [key])===「string」?result [key] .trim():result [key] SyntaxError:missing) – negrotico19
您使用的是哪個節點?複製時缺少某些內容,因爲這適用於瀏覽器和代碼片段。 –
(版本4.8.2) – negrotico19