Node.js 向客户端发送数据后控制台中出现的未知对象数组
我正试图通过socket.io发送一些数据。特别是,我正在发送一个包含纸牌游戏值的对象数组,例如Node.js 向客户端发送数据后控制台中出现的未知对象数组,node.js,socket.io,Node.js,Socket.io,我正试图通过socket.io发送一些数据。特别是,我正在发送一个包含纸牌游戏值的对象数组,例如 socket.emit('yourCard', deck.filter(x => x.playerId === userIds[i].id)); 服务器端的console.log将按预期提供此数组 [ { Value: '4', Suit: 'spades', id: 3, playerId: '-pFddkeoWzdPWZo4AAAB' }, {
socket.emit('yourCard', deck.filter(x => x.playerId === userIds[i].id));
服务器端的console.log将按预期提供此数组
[
{
Value: '4',
Suit: 'spades',
id: 3,
playerId: '-pFddkeoWzdPWZo4AAAB'
},
{
Value: '2',
Suit: 'diamonds',
id: 14,
playerId: '-pFddkeoWzdPWZo4AAAB'
}
]
客户端代码:
socket.on('yourCard',function(data){
console.log(data);
});
但在firefox客户端浏览器的控制台中,我看到了这一点
0: Object { Value: "10", Suit: "spades", id: 9, … }
1: Object { Value: "J", Suit: "spades", id: 10, … }
length: 2
<prototype>: []
concat: function concat()
constructor: function Array()
copyWithin: function copyWithin()
entries: function entries()
every: function every()
fill: function fill()
filter: function filter()
find: function find()
findIndex: function findIndex()
flat: function flat()
flatMap: function flatMap()
forEach: function forEach()
includes: function includes()
indexOf: function indexOf()
join: function join()
keys: function keys()
lastIndexOf: function lastIndexOf()
length: 0
map: function map()
pop: function pop()
push: function push()
reduce: function reduce()
reduceRight: function reduceRight()
reverse: function reverse()
shift: function shift()
slice: function slice()
some: function some()
sort: function sort()
splice: function splice()
toLocaleString: function toLocaleString()
toSource: function toSource()
toString: function toString()
unshift: function unshift()
values: function values()
Symbol(Symbol.iterator): function values()
Symbol(Symbol.unscopables): Object { copyWithin: true, entries: true, fill: true, … }
<prototype>: Object { … }
0:Object{Value:“10”,Suit:“spades”,id:9,…}
1:对象{Value:“J”,Suit:“spades”,id:10,…}
长度:2
: []
concat:函数concat()
构造函数:函数数组()
copyWithin:函数copyWithin()
条目:函数条目()
every:函数every()
fill:函数fill()
过滤器:函数过滤器()
find:函数find()
findIndex:函数findIndex()
flat:函数flat()
flatMap:函数flatMap()
forEach:函数forEach()
includes:函数includes()
indexOf:函数indexOf()
join:函数join()
键:功能键()
lastIndexOf:函数lastIndexOf()
长度:0
映射:函数映射()
函数pop()
push:函数push()
reduce:函数reduce()
reduceRight:函数reduceRight()
反向:函数反向()
移位:函数移位()
切片:函数切片()
some:函数some()
sort:函数sort()
拼接:函数拼接()
toLocaleString:函数toLocaleString()
toSource:函数toSource()
toString:函数toString()
unshift:函数unshift()
值:函数值()
Symbol(Symbol.iterator):函数值()
Symbol(Symbol.uncopables):对象{copyWithin:true,entries:true,fill:true,…}
:对象{…}
前三行是预期的,但我的问题是“这些对象是什么,如果我每40毫秒向客户端发送一个包,它们会影响性能吗?我可以/应该删除这些对象吗?”此外,发送普通字符串只会在控制台中返回字符串
非常感谢您对上述任何问题的解答。您看到的只是一个数组。数组在其原型中具有这些属性。(毕竟,您可以使用
[1,2,3].map
例如。)在控制台中尝试console.log([123456])
来了解我的意思。您是正确的。这回答了我的问题。