We don't always need to repeat information. Pronouns replace names and nouns and make our language more efficient.
Nice flower.
Thanks! Juan gave it (=the flower) to me.
Depending on the gender and number of what the pronoun is replacing, we say:
Juan me regaló un libro. Juan me regalo unos libros.Juan me lo regaló. Juan me los regaló.
Juan me regaló una flor. Juan me regaló unas flores.Juan me la regaló. Juan me las regaló.
On a slightly different topic, let's review the indirect (or recipient) pronouns for a moment:
YoMe regalaron una flor.
Te regalaron una flor.
Él/EllaLe regalaron una flor.
Now, let's combine both.
¿Y esta flor?
What's this flower?
Me la regalaron.
Someone gave it to me.
Te la regalaron.
Someone gave it to you.
Le la regalaron. → Se la regalaron a Pedro.
Someone gave it to Pedro.
Why Se?
Nobody really knows, but maybe it's because no one wants to say lelo or lela.
It means "fool".