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:

object.key

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.

08 Jul 2021

Website Design, Poster Design, Flyer Design or any creative design needs images or illustrations to convey the message. A plain textual design may not be successful all the time. Your freelance web designer Singapore must have advised you on the importance of images in the website. Not just images, quality images are a must. Not … Continue reading “What are Royalty free Stock Images – A Beginners Guide to Stock Images”

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: , , , , , ,

02 Feb 2021

Successfully you have hired a freelance web designer Singapore for your website design and development. Your website designer has requested a few answers from you for a set of questions, normally known as a website design questionnaire. As a business person you only know that you need a website which could help you bring in … Continue reading “The Ultimate Guide to Website Design Questionnaire”

Tags: , , , ,