There are two main ways in which World War II worked to get the US out of the Great Depression.
First, the US started to draft men into the military even before the country entered the war. The draft started in October of 1940. By drafting men into the military, the US government was alleviating the problem of unemployment. It was taking men out of the workforce. In the case of unemployed men, it meant that they now essentially had a job. In the case of men who had been employed, it opened their jobs up for others to take. Either way, it reduced unemployment.
Second, the war caused a massive boom in manufacturing. The US started to ramp up production of war materiel even before Pearl Harbor. It was making materiel to send to the Allies through the Lend-Lease program. It was also doing things like building ships in anticipation of the potential need to go to war. What this did was to give more people jobs. Once the US got into the war, of course, production boomed even more rapidly. By 1942, unemployment was at a very low level and GDP was up.
Thus, the war decreased unemployment drastically. It took men (and some women) into the military. It caused a need for a huge boom in production. These factors reduced unemployment and increased GDP, thus ending the Depression.