array/unshift.js

  1. import { applyArrayMethod } from './applyArrayMethod'
  2. /**
  3. * Replaces an array adding elements at the start 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. * unshift({ nested: { prop: [1, 2] } }, 'nested.prop', 3) // => { nested: { prop: [3, 1, 2] } }
  12. * @example <caption>Add several elements.</caption>
  13. * unshift({ nested: { prop: [1, 2] } }, 'nested.prop', 3, 4) // => { nested: { prop: [3, 4, 1, 2] } }
  14. * @see {@link https://mdn.io/Array.prototype.unshift|Array.prototype.unshift} for more information.
  15. * @since 0.1.7
  16. */
  17. const unshift = applyArrayMethod('unshift')
  18. export { unshift }