2

I got the following array:

var liList = $(".paging li");

Right now it's filled like this: ["Previous", "Next"].
Now I want to add numbers between those two items to get something like ["Previous", "1", "2", "Next"].
How do I do this? I want something like this:

var liList = $(".paging li");
for (var i = 1; i < 10; i++){
    liList.eq(i).add("li");
} 
1

1 Answer 1

1

You can use the array_splice function:

$(function() {
    var pagination = ["Previous", "Next"];
    for (i = 1; i <= 10; i++ ) {
        pagination.splice(i, 0, i);
    }
    console.log(pagination);
});

Output is:

 ["Previous", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "Next"]
Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't work with a JQuery array, does it? Or am I doing something else wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.