Q:

React js pagination - deleting null values from array

I'm trying to make pagination logic that would change page numbers when you click on the last index. 
E.G
1 2 3 4 5 

If user clicks on 5, it should change to
2 3 4 5 6

and so on ...
I managed to so, however I'm assigning first element to null, therefore my array is getting bigger, since I'm not deleting any element. 
I want to delete all null values in the array, and I tried to use various methods with underscore: _wihout, _reject, but it always gives me an error that _ is undefined.
This is the snippet of that particular code
 handleClick(event) {
        this.setState({
            currentPage: Number(event.target.id),
        })
        if (this.state.currentPage === this.state.pageNumbers[this.state.pageNumbers.length-1]) {
             this.state.pageNumbers.push(this.state.pageNumbers.length + 1);
             this.state.pageNumbers[this.state.startIndex] = null;
             this.state.startIndex++;
             this.state.pageNumbers._.without(array, null);
               // delete null values
        }
    }

A:

First of all the setState method is asynchronous. You have to keep that in mind and use the second parameter in setState(state, callback) to get the new state values. e.g.
this.setState({
    currentPage: Number(event.target.id),
}, () => {
    if (this.state.currentPage === this.state.pageNumbers[this.state.pageNumbers.length - 1]) {}
    // and so on
})

To filter null values out you don't need to use a third party library. You can use Array#filter to achieve it. Besides that you should not directly set the state fields with this.state.xy = yz.
To manipulate state variables it's always a great idea to make a new copy of it and assign it later with setState. Something along this:
const pageNumbers = Object.assign({}, this.state.pageNumbers); // copy
pageNumbers[this.state.startIndex] = null;
this.setState({
    pageNumbers: pageNumbers.filter(noNull => noNull),
    startIndex: this.state.startIndex + 1
});

