...

/

Array Methods and Properties

Array Methods and Properties

Overview of JavaScript methods and properties.

Introduction

Array objects, like other objects, have methods and properties that let you modify or query them onto the object. These methods and properties make it easy to manage data. It is more convenient to use arrays rather than creating custom objects.

Properties of an array

The property of an array is a quality or attribute of the array. This could be the length, memory size, or any other quality. These are usually static values updated with the array. They may also be used to change a certain quality of the object.

So let’s take a look at some important properties available to us through JavaScript.

> length

The length property, a widely used property, tells you the current length of the array. Since this property is updated as the array is updated, there is no computation overhead when this property is called upon.

Let’s see this in action.

Press + to interact
var arr1 = [1, 2, 3, 4, 5]; // assign array of 5 elements to arr1
var arr2 = new Array(100); // assign an array of size 100 to arr2
var arr3 = new Array(9, 10); // assign array with 2 eleements to arr3
console.log(`arr1 size:`, arr1.length); // print length of arr1
console.log(`arr2 size:`, arr2.length); // print length of arr2
console.log(`arr3 size:`, arr3.length); // print length of arr3
...