In a text, it has been written that a function is $|f\rangle= \sum_{j=1}^{\infty}a_j|\phi_j\rangle$, how one can write that -
$ |f\rangle= \sum_{j=1}^{\infty}|\phi_j\rangle\langle\phi_j|f\rangle$,
and
$ |f\rangle= (\sum_{j=1}^{\infty}|\phi_j\rangle\langle\phi_j|)|f\rangle$? plz show the derivation.
The text is given below-

We have $a_j=\langle \phi_j\mid f\rangle$. This immediately gives $$ \sum_{j=1}^{\infty}a_j|\phi_j\rangle=\sum_{j=1}^{\infty}\langle \phi_j\mid f\rangle |\phi_j\rangle $$ (You have an extra $a_j$ on the right-hand side here; that's a typo and not present in your image.)
Now consider the fact that $\langle \phi_j\mid f\rangle$ is just a number, so it commutes with $|\phi_j\rangle$, giving us $$ =\sum_{j=1}^{\infty}|\phi_j\rangle\langle \phi_j\mid f\rangle $$ Finally, Dirac notation multiplication is associative and distributive, so we may group the middle $\langle \phi_j|$ with the left-hand $|\phi_j\rangle$ rather than the right-hand $|f\rangle$, and move the $|f\rangle$ outside the sum.