1024programmer Java In JavaScript, are these two arrays the same? -php tutorial

In JavaScript, are these two arrays the same? -php tutorial

 var arr1 =new Array("Luffy","Zoro","Sanji");
     var arr2 =new Array("Cocoro","Qimonni","Kumbei","Iceberg");
     var arr3 =new Array("Kunis","Ganfulu","Weibo","Laki");

     var arrAll1 = new Array(arr1,arr2,arr3);
     console.log( arrAll1.toString() );


     arrAll2=new Array().concat(arr1,arr2,arr3)
     console.log( arrAll2.toString() );


 

Are arrAll1 and arrAll2 here the same array??

Anyway, it’s not a thing in PHP, but I don’t know if it is a thing here;

But using tostring here looks the same;

Reply content:

 var arr1 =new Array("Luffy","Zoro","Sanji");
     var arr2 =new Array("Cocoro","Qimonni","Kumbei","Iceberg");
     var arr3 =new Array("Kunis","Ganfulu","Weibo","Laki");

     var arrAll1 = new Array(arr1,arr2,arr3);
     console.log( arrAll1.toString() );


     arrAll2=new Array().concat(arr1,arr2,arr3)
     console.log( arrAll2.toString() );


 

Are arrAll1 and arrAll2 here the same array??

Anyway, it’s not a thing in PHP, but I don’t know if it is a thing here;

But using tostring here looks the same;

Obviously different. arrAll1 is a two-dimensional array, arrAll2 is a one-dimensional array

You will know when you visit:

arrAll1[0][0]; // "Luffy"
 arrAll2[0]; // "Luffy"

The answers are the same, but you will find that they have some differences, as follows:

arrAll1.length; //The result is 3
 arrAll2.length; //The result is 11

This is the difference, the first one just puts the three arrays together,
while the second one does take out each element of the three arrays separately and puts them into arrAll2

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/in-javascript-are-these-two-arrays-the-same-php-tutorial-2/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索