array/copyWithin.js

  1. import { applyArrayMethod } from './applyArrayMethod'
  2. /**
  3. * Shallow copies part of an array to another location in the same array, without modifying its size.
  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 {number} target Zero based index at which to copy the sequence to.
  9. * @param {number} [start] Zero based index at which to start copying elements from.
  10. * @param {number} [end] Zero based index at which to end copying elements from.
  11. * @return {Object} Returns the updated object.
  12. * @example copyWithin({ nested: { prop: [1, 2, 3, 4, 5] } }, 'nested.prop', 0, 3, 4) // => { nested: { prop: [4, 2, 3, 4, 5] } }
  13. * @see {@link https://mdn.io/Array.prototype.copyWithin|Array.prototype.copyWithin} for more information.
  14. * @since 2.0.0
  15. */
  16. const copyWithin = applyArrayMethod('copyWithin', {
  17. arity: 1,
  18. mutating: true,
  19. })
  20. export { copyWithin }