Associative arrays in Javascript

Associative arrays in Javascript

If you programmed in PHP, you are probably familiar with associative arrays. Associative arrays allow strings to be used as indices, not just numbers. Example:

var SE = new Array();

SE ['one'] = 1;

SE ['two'] = 2;

None of the methods of the Array class allows you to display elements of an associative array. The length property also does not work, so you cannot iterate over the elements of an associative array in a for loop. To do this, use the for ..in loop:

for (var SP in SE) {

  document.write(SP + " = " + SE[SP] + "<br>");

}

The output will be:

one = 1

two = 2

Popular Posts

My most popular posts

Maximum productivity on remote job
Business

Maximum productivity on remote job

I started my own business and intentionally did my best to work from anywhere in the world. Sometimes I sit with my office with a large 27-inch monitor in my apartment in Cheboksary. Sometimes I’m in the office or in some cafe in another city.

Hello! I am Sergey Emelyanov and I am hardworker
Business PHP

Hello! I am Sergey Emelyanov and I am hardworker

I am a programmer. I am an entrepreneur in my heart. I started making money from the age of 11, in the harsh 90s, handing over glassware to a local store and exchanging it for sweets. I earned so much that was enough for various snacks.

Hire Professional CRM developer for $25 per hour

I will make time for your project. Knowledge of Vtiger CRM, SuiteCRM, Laravel, and Vue.js. I offer cooperation options that will help you take advantage of external experience, optimize costs and reduce risks. Full transparency of all stages of work and accounting for time costs. Pay only development working hours after accepting the task. Accept PayPal and Payoneer payment systems. How to hire professional developer? Just fill in the form

Telegram
@sergeyem
Telephone
+4915211100235