Enforce using the separator argument with Array#join()
​
💼 This rule is enabled in the ✅ recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
It's better to make it clear what the separator is when calling Array#join(), instead of relying on the default comma (','
) separator.
Fail ​
js
const string = array.join();
js
const string = Array.prototype.join.call(arrayLike);
js
const string = [].join.call(arrayLike);
Pass ​
js
const string = array.join(',');
js
const string = array.join('|');
js
const string = Array.prototype.join.call(arrayLike, '');
js
const string = [].join.call(arrayLike, '\n');