[Solved] Why if JavaScript array.split(‘ ‘).push(‘something’) returns number, but not array? [duplicate]


Push returns the number of items in the collection, not the collection itself.

Try:

var currentItems = obj.className.split(' ');
currentItems.push(cls);
obj.className = currentItems

Instead of:
obj.className = obj.className.split(' ').push(cls);

1

solved Why if JavaScript array.split(‘ ‘).push(‘something’) returns number, but not array? [duplicate]