在JavaScript中删除数组中的双引号

问题描述 投票:1回答:3
var old_response = ["a,b,c","x,y,z","e,f,g"] 
new_response = ["a,b,c,x,y,z,e,f,g"]

目前我得到old_response而不是我需要new_response

javascript json node.js mongodb
3个回答
2
投票

只需使用Array#join方法连接元素并放入一个新数组。

var old_response = ["a,b,c","x,y,z","e,f,g"] ;

var new_response = [old_response.join()];

console.log(new_response);

2
投票

old_response = ["a,b,c","x,y,z","e,f,g"]
console.log([old_response.join()])

0
投票

您可以将数组转换为字符串:

var old_response = ["a,b,c","x,y,z","e,f,g"]
var new_response = [old_response.toString()]  // or [old_response + '']

console.log(new_response)
© www.soinside.com 2019 - 2024. All rights reserved.