I see three possibilities for understanding Job's situation:
We are meant to read the entire book of Job as allegory rather than as history.
Children were valued in a different way in Job's culture than they are in ours.
Job, whether he knew it or not, had a hope of resurrection.
These are not mutually exclusive options so let's see how they answer the question one-by-one.
There's a strong sense in most of Job that the framing story is merely the circumstances of the book and not the subject. Job seems to be a representative of a particular type of person: godly, but suffering. The bulk of the book is about how to resolve these seemingly contradictory traits. Symbolically, the losses of the first chapter are exactly doubled in the second chapter to show that God does bless the righteous in the end, even if there are times of suffering.
The number of children is not doubled, but the Job's family composition is restored in the end. It doesn't directly say new children were born to replace the ones who died, so there's an outside chance that the text implies a resurrection. More likely, the point of the allegory isn't that everything is completely restored as before to Job, but that having children is an undeserved blessing and that found contentment despite his loss.
View of Children
That brings me to the second possibility: children are valued more for continuing the family line than for their individuality in many cultures. Many of us have a problem with the loss of Job's children because we don't highly value group identity. It's entirely possible that this is the result of a cultural shift that occurred around the time that Christianity began. In any case, Job's society probably was more used to children dying and did not see them as irreplaceable the way you and I do.
Interestingly, the children of chapter 1 are not very well fleshed out as characters. They don't have names or identities the way the daughters in chapter 42 do. From a thematic viewpoint, the death of the children in the beginning is needed to bring Job down to the very depths of despair. Equally, the good end of the children of Job's later life can be seen as a blessing that would far outweigh the loss of any number of children from the proper cultural lens.
While neither Job nor the author of his book held an belief in an afterlife that comes anywhere close to Resurrection, there have been regular attempts to see that hope in the book since at least 132 BCE. According to N. T. Wright's comprehensive survey of the topic, the Jewish tradition shifted from the idea of Sheol (a dry, dusty, Hades-like existence for all the dead) to the idea of a resurrection of the righteous around the time of the Exile. He cites Daniel 12 as the pivotal text. In this light, Job may find hope in a future life with God both for himself and (presumably) for his children.
I think we should be careful about going too far down this road—especially when it comes to offering comfort to people who have lost children. I am reminded of the poignant scene in The Great Divorce by C. S. Lewis in which a ghost named Pam only wants to get to heaven in order to see her son:
"If [God] loved me He'd let me see my boy. If he loved me why did He take Michael away from me? I wasn't going to say anything about that. But it's pretty hard to forgive, you know."
We struggle as humans to understand the causes and purposes of suffering and Job is one of our primary texts to aid in that meditation. There aren't any easy answers about how Job could be content, but we do know the One who was able to offer him hope.