In Java, it is difficult to do easily with List.add, List.remove, and List.addAll with JavaScript, so I tried to summarize frequently used array operations.
Add element ʻitem to array ʻarray. In Java, List.add (). This operation modifies ʻarray` itself.
array.push(item)
Delete the element ʻitem in the array ʻarray. In Java, List.remove (item). This operation modifies ʻarray` itself.
const index = array.indexOf(item)
if (index >= 0) {
array.splice(index, 1)
}
Add element ʻitem to ** beginning ** of array ʻarray. In Java, List.add (0, item). This operation modifies ʻarray` itself.
array.unshift(item)
Add the array b to the array ʻa. In Java, List.addAll (b). This operation modifies ʻa itself.
a.splice(a.length, 0, ...b)
Create an array c by adding the array b to the array ʻa. ʻA itself ** does not change **.
c = a.concat(b)
Recommended Posts