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

  • SEARCH
  • Home
  • 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 9069863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:32:24+00:00 2026-06-16T17:32:24+00:00

I require to maintain only a specific number of elements in an Javascript array.

  • 0

I require to maintain only a specific number of elements in an Javascript array. Lets say only 10 items in the array. It should follow the FIFO concept, which means if there are 10 items on the array and a new item is added, then the item[0] should automatically be popped out of the array. Is there a way to do this or should I be doing the whole stuff programatically on Javascript 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-06-16T17:32:25+00:00Added an answer on June 16, 2026 at 5:32 pm

    I’d probably create my own object that has an array in it:

    var myArray = {
        arr: [],
        add: function(val) {
            this.arr.unshift(val);
            if (this.arr.length > 10) {
                this.arr.length = 10;
            }
        }
    };
    
    for (var i = 0; i < 15; i++) {
        myArray.add(i);
        //alert(myArray.arr.length);
    }​
    

    http://jsfiddle.net/6Nevz/2/

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

Sidebar

Related Questions

We're on Rails 3.0.6. We maintain a list of numbers that changes only once
One of the functionalities in my current flex application requires me to maintain a
require('fortunes') fortune('106') Personally I have never regretted trying not to underestimate my own future
require installed gems are not visible. Test with hpricot which I installed several times:
require 'coderay' puts CodeRay.scan('puts Hello, world!', :ruby).page This code will print full HTML page
require 'sinatra/base' class Foo < Sinatra::Base get('/foo') { 'foo' } end class Bar <
Require a huge help here, since this is affecting our production instance. One of
require_once('/recaptcha/recaptchalib.php'); was in the correct place but the error says: Warning: require_once() [function.require-once]: open_basedir
require 'open-uri' print Enter a URL add = gets open(#{add}) do |f| j =
I require ASP.NET server side code in a SVG that I created. To accomplish

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.