Hi @developer sp1 ,
Before running the code snippet, need to enable the Content Type Management for the library and add the Content Type needed in library settings,for example, I want to set Content Type "Images" for Item 7 which is an image:
Add the code using Script Editor Web Part:
Will set the content type successfully:
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.