我有以下功能它是工作,但我需要的數組排序正確 我會告訴你我的代碼,然後我會告訴你我的輸出,然後輸出我需要node.js中需要解決我的功能陣列輸出
編輯我完整的代碼和輸出
var app = require('express')()
, server = require('http').createServer(app)
, fs = require('fs')
, exec = require('child_process').exec
, io = require('socket.io').listen(server);
var async = require('async');
server.listen(process.env.PORT);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/client/index.html');
// console.log(async);
});
io.sockets.on('connection', function (socket) {
//socket.emit('dinpu', { hello: 'world' });
// myModule('[email protected]:asdfef');
socket.on('dout', function (data) {
//module2(data);
//console.log(JSON.parse(data.message));
for(i = 0; i < data.message.length; i++) {
//data.message[i] = data.message[i].replace(/"/g, "");
}
module1(data.message);
module2(data.message);
function module1(data) {
console.log(data);
}
function async(arg, callback) {
console.log('do something with \''+arg+'\', return 1 sec later');
setTimeout(function() { callback(arg * 2); }, 1000);
}
function module2(data) {
function final() { console.log('Done', results); }
var items = data;
var results = [];
function series(item) {
if(item) {
async(item, function(result) {
results.push(result);
return series(items.shift());
});
} else {
return final();
}
}
series(items.shift());
}
});
});
一切工作正常,除了這部分
function final() { console.log('Done', results); }
我得到的結果
do something with 'dfhfgh', return 1 sec later
do something with 'gfhjghj', return 1 sec later
do something with 'gfhjghj', return 1 sec later
do something with 'fghjgh', return 1 sec later
do something with 'ghjfhj', return 1 sec later
Done [ NaN, NaN, NaN, NaN, NaN ] < the problem
,如果引號不是在我的數組,那麼爲什麼在顯示出來的其他結果我不需要這個
你是說你需要將變量存儲在數組中,而不是字符串? – srquinn
我需要刪除'從陣列 – user3385289
你能說清楚你的問題嗎?您將其描述爲排序問題,但這些值不會更改當前和期望之間的順序。他們只是刪除了報價單。你想達到什麼目的? –