JSFiddle - React, Tailwind, and code Playground

JavaScript

function spinalCase(str) {
var str1;
var arr0=[];
arr0=str.split('')
arr0.forEach(
function(item, index){
if (item==='p'){
arr0.splice(index, 0, ' ')}
}
)

  console.log (arr0);
}

spinalCase('thisIsSpinalTap');