C
C
cester2018-02-07 11:23:47
JavaScript
cester, 2018-02-07 11:23:47

How to replace null in an array?

Good afternoon! Can you please tell me how to improve this?

const types = [
  null,
  null,
  'OPEN_MODAL',
  'CLOSE_MODAL',
];

that is, what can replace null? Doesn't look very good...
I want 'OPEN_MODAL' and 'CLOSE_MODAL' to be respectively where they are in the array.
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kovalsky, 2018-02-07
@lazalu68

const types = [];
types[2] = 'OPEN_MODAL';
types[3] = 'CLOSE_MODAL';

A
Anton Mashletov, 2018-02-07
@mashletov

The very fact that 'OPEN_MODAL must necessarily be at array index 2, and CLOSE_MODAL - at 3 does not look very good.

N
nluparev, 2018-02-07
@nluparev

see Null Object Pattern

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question