You Might Not Be Familiar with These Things about the JavaScript Array – 1

Every programming element is important. However, the array is special. It enables you to use a single variable to refer the storage of multiple variables. With an array, it has become much easier to handle multiple values. There are some limitations of this referenced data type. This is the reason why Java, C#, and other high-level languages rely on objects to store values of different primitive data types. However, still, arrays are very important element of middle and high-level programming languages.

Almost all programming languages have common properties for an array. In this article, we are going to discuss one of the three important things you probably do not know about JavaScript arrays.

Adding Custom Properties to Array

There are three types of properties that you can add to a JavaScript array.

Indices of an array

Predefined or built-in properties

Custom properties

Every beginner developer is familiar with the first two properties. Experienced developers regularly use all three properties.

Indices as Properties

In JavaScript, the syntax of creating an array is:

var ary = [“eyes”,”hands”,”ears”];

Indices are properties of array elements and are always positive integers. Just as we have a key-value pair in an object, we have an index-element pair in JavaScript array. Indices are different from other built-in properties of an array. A developer can set an element in the index with bracket syntax.

For example

ary[3] =”xyz”;

Built-In Properties

There are some properties that are frequently used by developers. Therefore, these properties are predefined in JavaScript library. One of the examples of built-in properties is length. These properties are also used to customize generic objects for different needs.

There are two ways for accessing built-in properties:


or, ary[“key”]

In var ary = [“eyes”,”hands”,”ears”];

ary.length will return 3 and ary[“length”] will also return 3.

Adding Custom Properties

In JavaScript array, usually, a developer needs not to create and add a custom property. This is the reason why beginners are not taught how they can create and add custom properties to a JavaScript array. However, a developer may encounter a special case in which he has to define and add a custom property.

In the following example, we have created a property to identify the class of an array.

Var ary=[“eyes”,”hands”,”ears”];

ary.itemClass =”bodyParts”;

console.log(ary+ ”are” +ary.itemClass);

The output will be “eyes, hands, ears are bodyParts”

Every program written in JavaScript or any other programming languages consists of at least one array. If you are working as a freelance website developer in Singapore, you know how important arrays are. Even if you are an experienced developer, there is still more to explore in JavaScript.

12 Apr 2023

In today’s digital age, having a strong online presence is crucial for individuals and businesses alike. Whether you’re launching an informational website, blog, an e-commerce site, or an online portfolio, your web page is often the first point of contact between you and your audience. That’s where domain and hosting come in. A domain is … Continue reading “Understanding Domain and Web Hosting: A Beginner’s Guide to Choosing the Right Service for Your Website”

Tags: ,

06 Dec 2022

A business’s logo is often the first thing customers and potential customers see. It sets the tone for how they perceive your company, products, and services. As such, it is essential to have a logo that accurately reflects who you are as a business and helps build a strong brand identity. A logo redesign can … Continue reading “Logo Redesign – How to do it right?”

Tags: , ,

15 Jun 2022

CMS stands for Content Management System; when you hire a freelance web designer in Singapore, they will provide the option for you whether you would like to build the website in Content Management System or a static informational website. As a business owner, you may be new to many terms in website design like CMS, … Continue reading “What is a CMS and Why should you use WordPress”

Tags: , , , , , ,