search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

首页课程Javascript fun classArray properties and methods

Array properties and methods

目录列表

数组属性和方法

数组属性和方法

length属性

JavaScript数组具有非常有用的内置属性和方法。

数组的 length 属性返回它的元素的数量。

var courses = ["HTML", "CSS", "JS"];
document.write(courses.length);
// -> 3

因为数组索引是从0开始的,所以 length 属性总是比最高的数组索引大1。如果数组为空则length属性的值为0


Array具有“length”属性,因为它是:

数组合并

数组合并

JavaScript的 concat() 方法允许您连接数组并创建一个全新的数组。

var c1 = ["HTML", "CSS"];
var c2 = ["JS", "Python"];
var courses = c1.concat(c2);

以上 courses 数组包含4个元素(HTML,CSS,JS,Python)。

concat 操作不会影响c1和c2数组 - 它会将所产生的连接作为新数组返 回。  


“concat”方法需要两个数组: