_.map

Translates all items in an array or object to new array of items.

  1. // Underscore/Lodash
  2. var array1 = [1, 2, 3]
  3. var array2 = _.map(array1, function (value, index) {
  4. return value * 2
  5. })
  6. console.log(array2)
  7. // output: [2, 4, 6]
  8.  
  9. // Native
  10. var array1 = [1, 2, 3]
  11. var array2 = array1.map(function (value, index) {
  12. return value * 2
  13. })
  14. console.log(array2)
  15. // output: [2, 4, 6]

Browser Support for Array.prototype.map()

ChromeEdgeFirefoxIEOperaSafari
1.5 ✔9.0 ✔