Elements added to an array should be used

  • USELESS_ARRAY
  • Code Quality
  • Low
  • No tags

This rule applies when an array becomes useless because elements added to the array are never used.

For maintainability, it is recommended to remove useless arrays. Also, it might be a mistake that a programmer forgets to use the array.

Noncompliant Code Example

View with compliant examples side by side
function makeMap(data) {
    var map = new Map();
    var keys = []; // USELESS_ARRAY alarm
    for (var i = 0; i < data.length; i++) {
        var key = data[i].key;
        var value = data[i].value;
        keys.push(key);
        map.set(key, value);
    }
    return map;
}

Compliant Code Example

View with noncompliant examples side by side
function makeMap(data) {
    var map = new Map();
    for (var i = 0; i < data.length; i++) {
        var key = data[i].key;
        var value = data[i].value;
        map.set(key, value);
    }
    return map;
}

Version

This rule was introduced in DeepScan 1.32.0.

Was this documentation helpful?