Home > Web Front-end > JS Tutorial > Introduction to JS array assignment_javascript skills

Introduction to JS array assignment_javascript skills

WBOY
Release: 2016-05-16 16:56:23
Original
1292 people have browsed it

Copy code The code is as follows:

var test=[1,2,3,4, 5,6,7];

var arr=test;
arr.splice(2,1);
alert(test);//1,2,4,5,6,7


JS arrays are essentially objects. Therefore, the above source code finally prints 1,2,3,4,5,6. This is because assigning test to arr actually assigns the reference of the array to arr, so operating arr will also

Change the source array.

To implement array cloning, the following methods can be used:

Copy the code The code is as follows:

Array.prototype.clone=function(){
return this.slice(0);
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template