Having problem with retrieving first 5 words from input

I have the following script which functionality should be to retrieve the first 5 words from one input and type them in a second input but it isn’t working as expected.

$('#review_content').on('keyup change paste click input', function () {
    
    var contentVal = $('#review_content').val();
    var contentValSplit = $('#review_content').val().split(' ');
    
    var headerValSplit = $('#review_header').val().split(' ');
    
    if(headerValSplit.length < 6) {
        if(contentValSplit.length > 6) {
            var $five = contentValSplit[0] + ' ' + contentValSplit[1] + ' ' + contentValSplit[2] + ' ' + contentValSplit[3] + ' ' + contentValSplit[4];
            $('#review_header').val($five + "...");
        } else {
            $('#review_header').val(contentVal + "...");
        }
    } 

});

When I paste longer text (longer than 5 words) the script is just pasting the same text in the second input but that’s not how it should work. It should get only the first 5 words from the whole text and paste only them in the second input. Or if the text is smaller than 5 words it should synchronously type the letters from the first input in the second one and stop after finishing the fifth word. Any ideas how to do that?