我对javascript数据处理有疑问

时间:2019-10-08 03:27:40

标签: javascript object

例如:

let array2 = [[{"Aaa":111}],[{"bbb":222}],[{"ccc":333}]];

我是初学者,如何将其变成?

[{"Aaa":111},{"bbb":222},{"ccc":333}]

2 个答案:

答案 0 :(得分:0)

您可以尝试像这样映射它:

array2 = array2.map(i=>{
  return i[0]
})

答案 1 :(得分:0)

您可以像这样使用javascript async promise函数:

const net = require('net');

const HOST = 'linux345';
const PORT = 2345;
let ErrCode = 1;

const client = new net.Socket();

client.connect(PORT, HOST, function() {
    ErrCode = 0;
});

client.on('data', function(data) {    
    console.log('Client received: ' + data);
     if (data.toString().endsWith('exit')) {
       client.destroy();
    }
});

client.on('close', function() {
});

client.on('error', function(err) {
    ErrCode = err.code;
    console.log(ErrCode);
});

console.log(ErrCode);

Learn more about the map function