
9 Code Assists for Arrays and Loops
JavaScript has several ways of defining loops and many array methods that work on the whole array. The JS Assistant provides several code actions for converting between different types of for loops and for converting to more idiomatic array methods such as array.includes().
- Convert array.filter()[0] to array.find()
Replace
anArray.filter(…)[0]
withanArray.find(…)
. - Convert array.indexOf() into array.includes()
Replace
array.indexOf()
checks witharray.includes()
. - Convert string comparison chain to array.includes()
Replace
|| value === 'aString'
and&& value !== 'aString'
chains witharray.includes()
. - Convert loop to .forEach
Replace regular
for
loops with.forEach()
loops. - Convert loop to for…of
Replace regular
for
loops andanArray.forEach
loops withfor…of
loops. - Convert loop to for
Replace
for…of
with a regularfor
loop that has an index variable. - Convert loop to .map()
Convert a loop with
.push()
into a.map()
call. - Move array element
Move an array element up or down.
- Move object property
Move an object property up or down.