Here i have one big array that has multiple arrays inside. I need to remove double quotes from each array. I tried all different methods to pull out quotes but none seem to work.
Current code produces this result:
[
["1,jone,matt,ny,none,doctor"],
["2,maria,lura,nj,some,engineer"],
["3,paul,kirk,la,none,artist"]
]
I need it this way:
[
[1,jone,matt,ny,none,doctor],
[2,maria,lura,nj,some,engineer],
[3,paul,kirk,la,none,artist]
]
const storeArray = [];
for(var i = 0; i < results.length; i++) {
var finalArray = results[i].id + "," + results[i].name + "," + results[i].lastname + "," + results[i].address + "," + results[i].status + "," + results[i].about;
storeArray.push([finalArray]);
}
res.send(storeArray);
You're creating strings as the first element of an array instead of an array of elements. You'll still have to contend with quotes because some of your data are strings - there's no getting round that - but this is closer to what you want.
const results = [ { id: 1, name: 'Andy', lastname: 'Jones', address: '999 Letsbe Avenue', status: 5, about: 'About' }, { id: 2, name: 'Sue', lastname: 'Barlow', address: '1 Fifth Street', status: 1, about: 'Another about' } ]; const storeArray = []; for (let i = 0; i < results.length; i++) { storeArray.push([ results[i].id, results[i].name, results[i].lastname, results[i].address, results[i].status, results[i].about ]); } console.log(storeArray);
Using split(',')
you can do that, try this code !
let results = [ ["1,jone,matt,ny,none,doctor"], ["2,maria,lura,nj,some,engineer"], ["3,paul,kirk,la,none,artist"] ] let storeArray = results.map((val) => val[0].split(',')); console.log(storeArray, 'storeArray');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.