检查对象的属性

时间:2016-11-02 23:26:58

标签: javascript

假设我有一个对象

var person = [{
  name: 'true',
  city: 'false'
}]

我有一个预定义的属性名称列表,我想查看

let props = ['name', 'address']

如何使用lodash _.includes进行检查?

我尝试过以下各种变体无效,全部返回错误

_.includes(person, [props]);
_.includes(person, 'name');
_.includes([person], 'name');

1 个答案:

答案 0 :(得分:0)

- 更新 - 鉴于您的更新说明,这就是获得所需结果的代码。

'use strict';
const socket = require('socket.io-client')('http://localhost:3000');
const ss = require('socket.io-stream');
const fs = require('fs');

var filename = 'test-copy.zip';

socket.on('connect', function () {
  console.log('connected');
  socket.emit('sendmeafile');
});

ss(socket).on('sending', function(stream) {
  stream.pipe(fs.createWriteStream(filename)); 
  stream.on('end', function () {
    console.log('file received');
  });
});