38 lines
676 B
Plaintext
38 lines
676 B
Plaintext
== Why is this an issue?
|
|
|
|
Associative arrays allow you to store values in an array with either numeric or named indexes. But creating and populating an object is just as easy as an array, and more reliable if you need named members.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
let arr = [];
|
|
arr[0] = 'a';
|
|
arr['name'] = 'bob'; // Noncompliant
|
|
arr[1] = 'foo';
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
let obj = {
|
|
name: 'bob',
|
|
arr: ['a', 'foo']
|
|
};
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::highlighting.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|