Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Case Suggestion: copywithin() #335

Open
adampicard opened this issue Dec 17, 2023 · 0 comments
Open

Use Case Suggestion: copywithin() #335

adampicard opened this issue Dec 17, 2023 · 0 comments

Comments

@adampicard
Copy link

How to copy part of an array to another location in the same array and returns the modified array without changing its length.

let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
fruits.copyWithin(3, 0, 2);
console.log(fruits); // Output: ['apple', 'banana', 'cherry', 'apple', 'banana']
  • 3 is the target index where the copying begins.

  • 0 is the start index from where to start copying elements (inclusive).

  • 2 is the end index where to end copying elements (not inclusive).

  • The elements 'apple' and 'banana' will be copied to indices 3 and 4.

  • The original elements at indices 3 and 4 ('date' and 'elderberry') will be overwritten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant