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 9259089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:34:18+00:00 2026-06-18T12:34:18+00:00

The alltones array contains all the possible notes in music scale. var alltones =

  • 0

The alltones array contains all the possible notes in music scale.

var alltones = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" ];

I want to take the user’s input of a tone, and then construct a list that contains certain elements of the array.

Say I start at alltones[5] or "F", and want to take every second element of the array from that point and put it into my list, until I get back around to "F". The array is more like a circle than straight list. I’m a little unsure of how the array operates once the loop reaches the last element.

Do I approach the problem by generating a new array, based on the users input. Or is there a way that JavaScript knows to loop back to the start of an array once it reaches the end such that it treats the array like a circle?

An example:
User input = F
The output that I am seeking is to count (every two items) from F until we get back around the array to F
so the desired output would be => F G A B C# D#

  • 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-18T12:34:20+00:00Added an answer on June 18, 2026 at 12:34 pm

    There isn’t an existing Array method to do what you want, but one is easily defined using Array.prototype.slice and Array.prototype.concat:

    // move i elements from the start of the array to the end of the array
    Array.prototype.lcycle = function(i) {
      var xs = this.slice(0,i);
      var ys = this.slice(i);
      return ys.concat(xs)
    };
    // move i elements from the end of the array to the start of the array
    Array.prototype.rcycle = function(i) {
      var xs = this.slice(0,-i);
      var ys = this.slice(-i);
      return ys.concat(xs);
    };
    

    And then you can use lcycle and rcycle as normal array methods:

    >>> alltones.lcycle(3)
    [ "D#" , "E" , "F" , "F#" , "G" , "G#" , "A" , "A#" , "B" , "C" , "C#" , "D" ]
    >>> alltones.rcycle(4)
    [ "G#" , "A" , "A#" , "B" , "C" , "C#" , "D" , "D#" , "E" , "F" , "F#" , "G" ]
    

    Note that both of these methods return a new array. If you wanted to mutate the original array, you could define similar methods using Array.prototype.splice.

    // move i elements from the start of the array to the end of the array, mutating the original array
    Array.prototype.lcycle_m = function(i) {
      var args = this.splice(0,i);
      args.unshift(0);
      args.unshift(this.length);
      this.splice.apply(this, args);
    };
    // move i elements from the end of the array to the start of the array, mutating the original array
    Array.prototype.rcycle_m = function(i) {
      var args = this.splice(-i);
      args.unshift(0);
      args.unshift(0);
      this.splice.apply(this, args);
    };
    

    And again, you can can use lcycle_m and rcycle_m as normal array methods:

    >>> alltones.lcycle_m(3)
    >>> alltones
    [ "D#" , "E" , "F" , "F#" , "G" , "G#" , "A" , "A#" , "B" , "C" , "C#" , "D" ]
    >>> alltones.rcycle_m(3)
    >>> alltones
    [ "C" , "C#" , "D" , "D#" , "E" , "F" , "F#" , "G" , "G#" , "A" , "A#" , "B" ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

< want to make a parcelable from an Object that contains an Arraylist, But
I have class Zones with properties and i want add data which i read
I need help checking if all the items in a two-dimensional list are the
So basically, i have successfully randomized certain pictureboxes in a grid to contain mines,
So basically, i have 2 int variables, x and y i am using to
I'm looking for something similar to Groovy's every() method, which tests every element of

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.