Languages
[Edit]
EN

JavaScript - code style for array (style guide - correct formatter for array)

3 points
Created by:
jarlh
635

In this article, we would like to show you code style for array in JavaScript.

Quick solution:

Note:
The main principle of creating an array is to make our code look clean.

Simple array example

Edit

To create an array we use square brackets [] by opening - [ and closing - ]; array in separate lines when our items are complex or just long. We place each item in a new line between the opening and closing bracket. As a separator for items we use comas ,.

Example for short/simple items:

Example for long/complex items: 

Array of objects example

Edit

Each object in the array should be placed in a new line and separated with coma ,.

Example:

Array of arrays example

Edit

For nested arrays, we mix the above rules - short items in one line, long or complex items in the separated line.

Example:

References:

Edit

Alternative titles

  1. JavaScript - default array formatter
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Dirask - content writing

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join