0

I have a Array that is pulling back X amount of Data from a JSON file, Lets say 40

I wanted some help where If i want X amount of data from that file, lets say just 20, What't the best approach to do so?

Is there any example out there.

I tried using jQuery.grep function but i was not getting it to work.

Any help will be greatly appreciated

Thanks in advance.

1 Answer 1

1

If the JSON "file" is a server-side script, then you could add a query string parameter to the request and then change the server-side code to restrict the number of results.

Otherwise, you can simply use the slice method of Array to get a subset of the array of data in your client-side code:

var subset = origArray.slice(20);
Sign up to request clarification or add additional context in comments.

2 Comments

I'm already getting the data using $.getJSON, i'm already getting all displayed on the page, not i just wanted some of the data, lets say I wanted data number more than 10 out of the entire 40
The server controls what you get sent, so check if the URL endpoint you're requesting with getJSON has some parameters to control how much data you're getting.

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.