如何删除单引号,把双引号中的JavaScript对象的数组中的[关闭]

问题描述 投票:-3回答:1

我想删除单引号,把双引号中的JavaScript对象在数组中。

var arr=[{ email: '[email protected]', name: 'Abc' },
         { email: '[email protected]', name: 'Dr.Def' },
         { email: '[email protected]', name: 'Xyz' },
         { email: '[email protected]', name: 'Cad' }];

我想输出是这样的:

var arr=[{"email":"[email protected]","name":"Abc"},
         {"email":"[email protected]","name":"Dr.Def"},
         {"email":"[email protected]","name":"Xyz"},
         {"email":"[email protected]","name":"Cad"}];
javascript arrays object double-quotes single-quotes
1个回答
1
投票

只是字符串化整个阵列?

var arr=[{ email: '[email protected]', name: 'Abc' },
         { email: '[email protected]', name: 'Dr.Def' },
         { email: '[email protected]', name: 'Xyz' },
         { email: '[email protected]', name: 'Cad' }];
         
 console.log(JSON.stringify(arr))

如果你想var arr =也只是在前面加上它console.log('var arr = ' + JSON.stringify(arr))

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