Working with objects is the only way to manipulate arrays or any other object in the JavaScript language. For example, it is necessary to implement a client list. The object can be implemented as follows:

 

Function CreateClients (name, address, telephone, rent)

{

this.name = name;

this.address = address;

this. phone = phone;

this.income = income;

}

The property “this” specifies the current object as a source of values ​​passed to the function. Now, just create the object:

 

Maria = New CreateClients (‘Maria Aparecida’, ‘Guillotine Rua dos Patos, S / N’, ‘332-1148’, 1300)

 

To access the properties of Maria object, simply use the following syntax:

Maria.name -> returns ‘Maria Aparecida’

Maria.address -> returns ‘Guillotine Rua dos Patos, S / N’

Maria.phone -> returns ‘332-1148’

Maria.income -> returns in 1300

Objects in Javascript

Another way to reference the properties of Maria’s object is:

Maria [0], Maria [1] Maria [2] Maria [3]

 

To create arrays, a more practical approach could be the following:

Function Matrix (n)

{

this.length = n

for (var counter = 1; counter <= n; conatdor = counter + 1)

{

this [counter] = “”

}

}

 

To create our array, then we would use the following command:

Month = matrix (12)

 

The next step would include only the data:

Month [1] = ‘January’

Month [2] = ‘February’

Month [12] = ‘December’

 

Finally, it is also possible to use both methods simultaneously:

New customers = Array (3)

Clients [1] = New CreateClients (“Charlene”, “Street A 51”, “331-0376”, 1150)

Customers [2] = New CreateClients (“Joseph”, “Street of Covenants, S / N,” “332-2781”, 950)

Customers [3] = New CreateClients (“James Manson,” “Joy Street, 171 ‘, 1000)

 

So obtaining the following scenario:

Customers [1] .name = “Charlene”

Customers [2] .phone = “332-2781”

Customers [3] = null .phone

Visit our blog and check out more content!

By ,

February 24, 2016

a

You might also like…

AI-Driven Software Development: The Role of ChatGPT

In the rapidly evolving world of technology, artificial intelligence (AI) is playing an increasingl...

Low-Code: The Key to Accessible Digital Transformation

Digital transformation is imperative for companies wishing to remain competitive in the current era...

Low-code: Simplifying Development Without Sacrificing Quality

In today's agile and competitive world, productivity is crucial for the success of any business. Th...

You might also like…

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.