例:
var array1 = [ {'key':1, 'property1': 'x'}, {'key':2, 'property1': 'y'} ]
var array2 = [ {'key':2, 'property2': 'a'}, {'key':1, 'property2': 'b'} ]
Run Code Online (Sandbox Code Playgroud)
我想合并(array1,array2)给我:
[
{'key':1, 'property1': 'x', 'property2' : 'b'},
{'key':2, 'property1': 'y', 'property2' : 'a'}
]
Run Code Online (Sandbox Code Playgroud)
是否有捷径可寻?
编辑:有几个人已经回答,没有仔细看我的问题,请注意我想匹配每个数组中的类似对象,并将他们的属性组合到我的最终数组.键是唯一的,每个阵列中最多只有一个具有特定键的对象.
为什么以下代码会因超时而失败?看起来“应该”抛出错误并且 done() 永远不会被调用?如何编写此测试以使其正确失败而不是让 jasmine 报告超时?
var Promise = require('bluebird');
var should = require('chai').should();
describe('test', function () {
it('should work', function (done) {
Promise.resolve(3)
.then(function (num) {
num.should.equal(4);
done();
});
});
});
Run Code Online (Sandbox Code Playgroud)
控制台输出是:
c:>茉莉花节点规范\
未处理的拒绝 AssertionError:预期 3 等于 4 ...失败:1)测试应该工作消息:超时:等待规范完成 5000 毫秒后超时
我读过几篇关于删除 require.cache['path to module'] 的文章,就像这样:http ://blog.alexanderseville.com/post/31919659559/un-require-in-nodejs
但它对我没有用。在我的节点文件中,我有这两行:
var fileToJsonParser = require('xls-to-json');
删除 require.cache[require.resolve('xls-to-json')];
我在 Windows 上运行并在任务管理器中观察内存使用情况。如果没有这两行,node.exe 的内存使用量约为 30 MB,但是一旦我需要“xls-to-json”,即使我尝试删除 require.cache,内存使用量也会上升到 120 MB。