Yeah most definitely, but how viable it actually was, the commonness of it and the reasons for doing it varied depending on who they were fighting and what stage of the war you're looking at. There's also a difference between say, a single soldier or small group making a charge or becoming involved in a hand-to-hand fight on their own and huge, massed banzai attacks involving hundreds or thousands of men charging simultaneously.
Within the Second Sino-Japanese War it could have been a valid offensive tactic. In the real battles the Japanese were typically on the offensive and were an exceedingly...brutal conquering force. The Chinese in practically all instances had inferior firepower (in particular very few automatic weapons, they used captured Japanese MGs extensively), were usually otherwise underequipped and typically had lower numbers and morale. When a larger, better trained force charges at a smaller, less prepared one...it's not gonna end when for the smaller one when they get there, provided they don't just run off beforehand. The conflict saw a lot of brutal urban warfare (especially Battle of Shanghai, 1937) where at this time melee fighting would often occur simply because of the cramped, chaotic conditions, even in places like Stalingrad a few years later where SMGs were relatively common. Another thing is some Chinese units were issued with dadao swords, though I'm not sure whether they were used in a more offensive or defensive manner.
Later in the war banzai charges were not seen as a viable tactic against US forces mainly due to their superior firepower (especially compared to Chinese forces) making it so that a lot, or even all of the attackers were gunned down before they even reached the enemy and the Japanese being on the defensive for the most part for the rest of the war. Massed banzai charges were however often launched as a kind of desperation/suicide attack towards the end of more or less lost battles. The most notable case is probably Saipan where the Japanese managed to take back a lot of ground and do a lot of damage within a short amount of time but were practically wiped out in the process. These kind of charges were mainly seen as a last ditch effort, a way to die with honour whilst hopefully killing as many of the enemy as possible. I don't think any reasonable commander would've expected a desperate banzai attack to actually turn the tide.
I'm not sure to what extent full-on banzai charges were used when fighting Commonwealth forces. Hand-to-hand engagements were common throughout the Pacific/South-East Asian Theatre, the dense jungle meant both sides were often very close together. It's worth noting that British and Commonwealth forces generally held the bayonet in higher regard than pretty much everybody but Japan (and they had Gurkhas).
As for the IJA pre-WW2 I remember reading an account of the Russo-Japanese War of 1904-1906 in CJ Chivers book The Gun (about the AK-47 and preceding automatic weapons, good read). The Japanese charged a Russian position equipped with Maxim guns over and over again until they took it, despite taking disproportionately high casualties. To be fair this was when just about everyone had a Napoleonic Wars-esque mentality to warfare, you could perhaps argue that any other army would've done the same thing (indeed they bloody did over and over again 10 years later...).