Is it possible to display the word shahi as the first word and amrit after '', but is there a way to display the last word using code? Any help would be appreciated.
function cap(cht){
var part1 = [];
var data = cht.split("") //['a', 'm', 'r', 'i', 't', ' ', 's', 'h', 'a', 'h', 'i']
for (var i = 0; i<data.length; i++){
if(data[i] === ' '){
break;
}
part1.push(data[i]);
}
console.log(part1)
}
document.write(cap('amrit shahi'));
Output: ['a', 'm', 'r', 'i', 't']
Similarly, I would like to display "shahi" if I console log it.