Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 907093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:29:47+00:00 2026-05-15T16:29:47+00:00

I am creating a JSON array exactly as follows (bar using mathrandom). For example

  • 0

I am creating a JSON array exactly as follows (bar using mathrandom).

For example purposes:

var numbers = [];
var jsonString = "";

function EveryOneSec() {
  numbers.push(Math.random());
  jsonString = JSON.stringify({'numbers': numbers});
  setTimeout(EveryOneSec, 1000);
}

When I create the JSON string it will obviously just keep getting bigger.

Is there a way that I can only have the 10 most recently added into the array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:29:47+00:00Added an answer on May 15, 2026 at 4:29 pm

    Add the following code to the top of EveryOneSec

    if (numbers.length == 10) {
        numbers.shift();
    }
    

    You want to use push and shift to ensure you always have the recent 10.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

right now I'm creating an array and using: render :json => @comments This would
I'm creating a JSON object like tags = {jon:[beef,pork],jane:[chicken,lamb]}; which was generated using php
Am creating a script using JQuery on an ASP.NET page. Have a JSON string
what I am doing is creating a form using JSON this form can then
I am creating a form dynamically from the fields returned from server using json
I'm creating a JSON feed with PHP using echo json_encode($my_array) . The resulting string
I am creating a multidimensional array for sections / rows based on json data
I am having trouble with loading JSON into an app that im creating $(#load_basic).click(function(){
I'm using json simple to create and parse some json. However, after creating it,
I am creating a json array in PHP like this (it's inside a class):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.