简体   繁体   中英

Concat several arrays in JavaScript (nodejs)

What would be the more concise way to concat all ar arrays in the following object:

var obj = {
  field1: {
    ar: [...]
  },
  field2: {
    ar: [...]
  },
  ...
  fieldN: {
    ar: [...]
  }
}

I found this:

Object.keys(obj).reduce(function(array, entry) {
  return array.concat(obj[entry].files);
}, []);

您可以这样尝试:

[].concat.apply([], [array1, array2, ...])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM