DONATE  
MENU
PHP
JSON
AJAX
CSS
JAVASCRIPT
HTML
MYSQL

JavaScript Tutorials

INTRODUCTION

» Introduction to JavaScript

» Practice IT Editor

» JavaScript Example

» JavaScript Placement

» JavaScript Syntax

» JavaScript Statements

» JavaScript Input

» JavaScript Output

» JavaScript Comments

» JavaScript Variables

» Variables' Scope

» JavaScript Operators

» JS Expressions & Concatenation

» JavaScript Data Type

» JavaScript Numbers

» Number Object

» JavaScript Strings

» String Object

» JavaScript Booleans

» Boolean Object

» JavaScript Functions

» JavaScript Arrays

» Array Object - Properties

» Array Object - Methods

» JavaScript Objects

» JavaScript Undefined

» JavaScript Nulls

CONDITIONAL TESTING

» If Statement

» If Else Statement

» JavaScript Ternary Operator

» Switch Statement

LOOPS

» For Loops

» While Loops

» Break & Continue

» For...In Loops

» do...while Loop

FUNCTIONS

» JavaScript Functions

» Creating Functions

» Functions' Parameters

» Functions' Arguments

» Function Invocation

» The Return Keyword

» The Arguments Object

» Callback Functions

» Arrow Functions

ARRAYS

» JavaScript Arrays

» Creating Arrays

» Accessing Arrays

» Looping Arrays

» Multi - dimensional Arrays

OBJECTS

» JavaScript Objects

» Creating Objects

» Prototype Definition

» Accessing Objects

» The this Keyword

AJAX

» Introduction to AJAX

JSON

» Introduction to JSON

JAVASCRIPT DATES

» The Date Object

» Date Methods

» Timing (SetInterval & SetTimeout)

MATH OBJECT

» Math Object

» Math Methods

HTML / JS DOM

» DOM Introduction

» Accessing HTML Elements in DOM

» Get And Change Elements' Contents & Values

» Change Styling - DOM CSS

» DOM Attributes

» JavaScript Event Listeners

» DOM Event Listeners

» JS Events

MISCELLANEOUS

» JS Strict Mode

» JavaScript Hoisting

» JavaScript let keyword

» Reserved Keywords

» JS Best Practices

» JavaScript vs ECMAScript

JAVASCRIPT EXAMPLES

» JavaScript Calculator

.. » JavaScript » Introduction » Array Object - Properties
Share Tweet WhatsApp

Array Object - Properties

From previous pages, you have learnt that JavaScript arrays have an object. We will discuss about that object in this page. Arrays can directly be created from the object,
var arr = new Array(1, "Hello World", true);
Nevertheless, It is best to create arrays using the explicit method e.g var arr = [1, "Hello World", true];. The array object have various properties and methods that can be used in manipulating all JavaScript arrays whether created from the arrays' object or using the explicit method of creating arrays. In this page, we shall get familiarized with some of these properties and methods. Properties 1. length The length property of an array returns the number of individual values contained in an array.
<script>
var myArray = [1, 2, 3, 4];

var len = myArray.length; //The length of the array
alert(len); //4
</script>

Copy PRACTICE IT

2. prototype The prototype property is a static property that allows you to add new properties or methods to the prototype from which every array object is created. By doing this, you can define new properties and methods every created array object will have in a document or script.
<script>
//Adding a new property... The object of every array will have this property just as they have the length property
Array.prototype.isArray = true;

//A function to check if variable or value is an array
function isArray(arr){
if (arr !== undefined && arr.isArray !== undefined && arr.isArray == true)
{
return "Array";
}
else
{
return false;
}
}

var array = [1,3,5];
alert(isArray(array)); //Array
alert(isArray([])); //Array
alert(isArray("Hello World")); //Not Array
</script>

Copy PRACTICE IT

Above, we wanted to define a function to know if a variable is an array or not. So, first, we added a new property(isArray) whose value is true to the prototype used in creating arrays' object. This ensures that whenever an array is created, its object also have this property. Now, whenever a value is passed to the function, the function checks to know if the value has this new property and whether the value is equal to true. If true, it is an array. 3. constructor This property contains the function used in defining the prototype from which an array object is created. Since, the Array prototype was predefined i.e it was defined in JavaScript by default and not by you, there is a limit to what you can see.
<script>
var arr = ["Hello World"];
alert(arr.constructor);
</script>

Copy PRACTICE IT

Check next page for the Array object methods. SUMMARY
  1. All JavaScript arrays whether created explicitly or implicitly has an object containing properties and methods.
  2. The length property enables you to know the number of values in an array.
  3. The prototype property just like every object's prototype property enables you to modify the prototype used in creating objects for arrays. You can then add or modify properties and methods of the array prototype so that every array object possesses these changes.
  4. The constructor property returns the object constructor that was used in defining the prototype for creating arrays' objects.
Take a short quiz on Array Object - Properties.
Ask a question or tell us if Array Object - Properties is easy or not.
cent?

Join our 1,090 subscribers to receive tutorials' updates!

  We won't spam your mail box. We hate it.





StackBeginner 2021 © Joseph Omamode