Would like to to display the word shahi as able to display first-word amrit after '', is there any way to display last word using code. help appricated.
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']
likewise i would like to display shahi if i console log.