zipObject.js 402 B

1234567891011121314151617181920
  1. var values = require('./values')
  2. var each = require('./each')
  3. /**
  4. * 根据键数组、值数组对转换为对象
  5. *
  6. * @param {Array} props 键数组
  7. * @param {Number} arr 值数组
  8. * @return {Object}
  9. */
  10. function zipObject (props, arr) {
  11. var result = {}
  12. arr = arr || []
  13. each(values(props), function (val, key) {
  14. result[val] = arr[key]
  15. })
  16. return result
  17. }
  18. module.exports = zipObject