Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript Arrays

JS Arrays

An array is a special variable, which can hold more than one value

					 
        
          const services = ["Website", "Applications", "Software"];
        
      
Why Use Arrays?

Array can be used to group similar type of data in a single variable. For example, storing a large data of mobile phone names in a single variable and access it via index.

Creating an Array

Array can be created using new keyword or using array literals. Array literal is the easiest way to create a JavaScript Array

					 
        
          // using new keyword
          const services1 = new Array();
          const services2 = new Array("Website", "Applications", "Software");

          // using array literals
          const services3 = [];
          const services4 = ["Website", "Applications", "Software"];
        
      
Accessing Array Elements

You access an array element by referring to the index number.

Array index start from 0. It means, first element is [0], second element is [1], and so on.

					 
        
          const services = ["Website", "Applications", "Software"];
          services[0];  // Website
          services[1];  // Applications
          services[2];  // Software
        
      
Changing an Array Element
					 
        
          const services = ["Website", "Applications", "Software"];
          services[0] = "Designing";
          services[1] = "Marketing";
          services[2] = "Consulting";
        
      
Converting an Array to a String

The JavaScript method toString() converts an array to a string of (comma separated) array values

					 
        
          const services = ["Website", "Applications", "Software"];
          services.toString();  // Website,Applications,Software

          // Below line automatically convert array to string
          services;  // Website,Applications,Software
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved