【发布时间】:2015-05-23 09:38:15
【问题描述】:
我有一个包含几个数组的数组,每个数组包含几个对象,类似于这个。
[[object1, object2],[object1],[object1,object2,object3]]
这是记录到控制台的对象的屏幕截图。
将其展平为对象数组的最佳方法是什么?
我试过这个没有运气:
console.log(searchData);
var m = [].concat.apply([],searchData);
console.log(m);
searchData 注销了上面的截图,但是 m 注销了 [ ]
这里是searchData的实际内容:
[[{"_id":"55064111d06b96d974937a6f","title":"Generic Title","shortname":"generic-title","contents":"<p>The Healing Center offers practical, social, and spiritual support to individuals and families. Services include, but are not limited to: food and clothing, job skills training and job search assistance, auto repair (Saturdays only), mentoring, financial counseling, tutoring, prayer, life skills training, and helpful information about local community services.</p><p>Stay in touch with us:</p>","__v":0},{"_id":"5508e1405c621d4aad2d2969","title":"test english","shortname":"test-page","contents":"<h2>English Test</h2>","__v":0}],[{"_id":"550b336f33a326aaee84f883","shortname":"ok-url","title":"now english","contents":"<p>okokko</p>","category":"Transportation","__v":0}]]
【问题讨论】:
-
我喜欢
arr.reduce(function(a,b){return a.concat(b);}); -
出于某种原因,这给了我一个空的 [ ]。我尝试过的其他几种方法也有...我不知道为什么?
-
如果提供的所有选项都不起作用,那你就做错了。
-
你能把searchData的内容也发一下吗?
标签: javascript arrays loops flatten