Skip to content
Advertisements

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”]

Advertisements

2 Comments »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: