array/push.js

  1. import { applyArrayMethod } from './applyArrayMethod'
  2. /**
  3. * Replaces an array adding one or more elements to the end of the former array.
  4. * @function
  5. * @memberof array
  6. * @param {Object} object The object to modify.
  7. * @param {Array|string} path The path of the property to set.
  8. * @param {...*} values The values to add.
  9. * @return {Object} Returns the updated object.
  10. * @example <caption>Add one element.</caption>
  11. * push({ nested: { prop: [1, 2] } }, 'nested.prop', 3) // => { nested: { prop: [1, 2, 3] } }
  12. * @example <caption>Add several elements.</caption>
  13. * push({ nested: { prop: [1, 2] } }, 'nested.prop', 3, 4) // => { nested: { prop: [1, 2, 3, 4] } }
  14. * @see {@link https://mdn.io/Array.prototype.push|Array.prototype.push} for more information.
  15. * @since 0.1.7
  16. */
  17. const push = applyArrayMethod('push')
  18. export { push }