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.

Types of Website Design in Singapore - Subraa

13 Sep 2023

Websites are more important for a business. As a freelance web designer in Singapore with over 14+ years of experience in the industry, we understand that your website is the visual storefront and your primary online presence. Your website is a gateway for potential customers to reach out to your products or services if you … Continue reading “Types of Website Designs in Singapore – Unleash the potential of your website with Subraa”

Tags: , ,
What are Royalty Free Stock Images - A Guide by Subraa, Freelance Web Designer in Singapore

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

07 Jun 2016

It is obvious that you probably must be planning to become a freelance web developer, designer or a blend of both if you are going through this article. You have been through all the diligent work and learned to code, yet now it’s an ideal opportunity to harvest a portion of the rewards that having … Continue reading “Freelance Web Developer – A Brief Career Guide”