javascript - automaticly genereated Set of values in a Array? -
how make array contain data values of varible random on time.
im getting distance value varible 'rssi' on time. save each postion along others in array 'arr'
this should done in javascript.
var express = require('express'); var app = express(); var server = require('http').createserver(app); var io = require('socket.io')(server); var port = process.env.port || 8000; var rssi = {}; server.listen(port,function(){ console.log('server listening @ port %d', port); }); // routing app.use(express.static(__dirname + '/public')); // server configuration var scanner = io.of('/scanner'); scanner.on('connection',function(socket){ console.log('scanner connected'); socket.on('devicedata1',function(msg) { var rssi = msg.rssi; var arr = []; arr.push(rssi); console.log(arr); }); });
the result 1 value of rssi in array.
example = [89] . = [20] need thing arr = [89 ,20 ,56]
you need declare arr
outside on
method
var arr = []; scanner.on('connection',function(socket){ console.log('scanner connected'); socket.on('devicedata1',function(msg) { var rssi = msg.rssi; arr.push(rssi); console.log(arr); });
now arr
show values have been added , when on
method called.
Comments
Post a Comment