Array copyWithin()

The copyWithin() method copies part of an array to the same array and returns it, without modifying its.

Syntax:

list.copyWithin(target[, start[, end]])

Field of application: When we need to copy the contents of any directory to the same array at the same time, we use array.copyWithin () in javaScript.

The CopyWithin function is a variable method. The array length does not change.


Examples

        var list = ["john", "alice", "oliver", "sasha"];
        console.log(list.copyWithin(0,1))

output:
[“alice”, “oliver”, “sasha”, “sasha”]


        var list = ["john", "alice", "oliver", "sasha"];
        console.log(list.copyWithin(1,2))

output:
[“john”, “oliver”, “sasha”, “sasha”]


        var list = ["john", "alice", "oliver", "sasha"];
        console.log(list.copyWithin(2,3))

output:
[“john”, “alice”, “sasha”, “sasha”]

2 thoughts on “Array copyWithin()

Add yours

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started