You can access an element at a specific index using the bracket notation accessor.

var valueAtIndex1 = myValues[1];

On newer browsers/JavaScript engines (see browser compatibility here), you can also use the .at() method on arrays.

var valueAtIndex1 = myValues.at(1);

On positive indexes, both methods work the same (the first one being more common). Array.prototype.at() however allows you to access elements starting from the end of the array by passing a negative number. Passing -1 will give the last element of the array, passing -2 the second last, etc.

See more details at the MDN documentation.

Answer from Abdul Munim on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › values
Array.prototype.values() - JavaScript | MDN
The values() method of Array instances returns a new array iterator object that iterates the value of each item in the array.
🌐
W3Schools
w3schools.com › jsref › › jsref_values.asp
JavaScript Array values() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-values-method
JavaScript Array values() Method - GeeksforGeeks
June 7, 2025 - JavaScript array.values() is an inbuilt method in JavaScript that is used to return a new array Iterator object that contains the values for each index in the array i.e., it prints all the elements of the array.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
Both the original and new array refer to the same object. That is, if a referenced object is modified, the changes are visible to both the new and original arrays. Primitive types such as strings, numbers and booleans (not String, Number, and Boolean objects): their values are copied into the new array.
🌐
W3Schools
w3schools.com › js › js_arrays.asp
JavaScript Arrays
An array can hold many values under a single name, and you can access the values by referring to an index number. Using an array literal is the easiest way to create a JavaScript Array.
🌐
Programiz
programiz.com › javascript › library › array › values
JavaScript Array values() (with Examples)
In this tutorial, you will learn about the JavaScript Array value() method with the help of examples.The values() method returns a new Array Iterator object that contains the values for each index in the array.
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-array
JavaScript Arrays: Create, Access, Add & Remove Elements
JavaScript array is a special type of variable, which can store multiple values using a special syntax. Learn what is an array and how to create, add, remove elements from an array in JavaScript.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Array › values
JavaScript Array values() - Get Array Values | Vultr Docs
November 29, 2024 - In JavaScript, arrays are fundamental structures used to store collections of data. One of the methods provided to interact with arrays is values(), which returns a new Array Iterator object that contains the values for each index in the array.
Find elsewhere
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Arrays
Create an array styles with items “Jazz” and “Blues”. Append “Rock-n-Roll” to the end. Replace the value in the middle with “Classics”. Your code for finding the middle value should work for any arrays with odd length.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › find
Array.prototype.find() - JavaScript | MDN
Again, it checks each element for equality with the value instead of using a testing function. If you need to find if any element satisfies the provided testing function, use some(). If you need to find all elements that satisfy the provided testing function, use filter(). const array = [5, 12, 8, 130, 44]; const found = array.find((element) => element > 10); console.log(found); // Expected output: 12
🌐
Mimo
mimo.org › glossary › javascript › arrays
Learn how to Use JavaScript Arrays: Create, Filter, Sort
A JavaScript array is a special variable that can hold more than one value at a time. Arrays are created using square brackets [], and the values inside are separated by commas.
Top answer
1 of 8
9

If you are OK with manipulating your original array as you loop through it you could splice and concat similar to below (or you could use a clone of the array if you need to persist the original array):

var myStringArray = ["1","2","3","4","5","6","7","8","9","10"];

var loopByX = function(x){
  var y = myStringArray.splice(0,x);
  myStringArray = myStringArray.concat(y);
  
  return y;
}

console.log(loopByX(3));
console.log(loopByX(3));
console.log(loopByX(3));
console.log(loopByX(3));
console.log(loopByX(3));

If you want to go bi-directional (is that what you call it?), as mentioned in the comments, you could do it as below which then gives you the ability to go backwards or forward and the flexibility to do so in an arbitrary number:

var myStringArray = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];

var loopByX = function(x) {
  var len = myStringArray.length;

  // Ensure x is always valid but you can add any behaviour here in that case yourself. As an example I return an empty array.
  if (Math.abs(x) > len) {
    return [];
  }

  var y = x > 0 ? myStringArray.splice(0, x) : myStringArray.splice(len + x, len);

  myStringArray = x > 0 ? myStringArray.concat(y) : y.concat(myStringArray);

  return y;
}

console.log(loopByX(20)); // invalid number
console.log(loopByX(-20)); // invalid number
console.log(loopByX(-3));
console.log(loopByX(-6));
console.log(loopByX(3));
console.log(loopByX(4));

2 of 8
4

You could take a function which slices three elements and if not possible, it takes the needed first values of the array as well.

function take3() {
    var temp = array.slice(index, index += 3)
    index %= array.length;
    console.log(temp.concat(temp.length < 3 ? array.slice(0, index) : []).join(' '));
}

var array = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"],
    index = 0;
<button onclick="take3()">take 3</button>

With a mapping of a dynamic count.

function take(length) {
    console.log(Array.from({ length }, _ => array[++index, index %= array.length]));
}

var array = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"],
    index = -1;
<button onclick="take(3)">take 3</button>

🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript arrays
JavaScript Array
November 15, 2024 - In JavaScript, an array is an order list of values; each value is called an element specified by an index.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › includes
Array.prototype.includes() - JavaScript | MDN
It only expects the this value to have a length property and integer-keyed properties. ... [1, 2, 3].includes(2); // true [1, 2, 3].includes(4); // false [1, 2, 3].includes(3, 3); // false [1, 2, 3].includes(3, -1); // true [1, 2, NaN].includes(NaN); // true ["1", "2", "3"].includes(3); // false · If fromIndex is greater than or equal to the length of the array, false is returned.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-arrays
JavaScript Arrays - GeeksforGeeks
And what if you had not 3 cars, but 300? The solution is an array! An array can hold many values under a single name, and you can access the values by referring to an index number.
Published   October 3, 2025
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Object › values
Object.values() - JavaScript | MDN
Object.values() returns an array whose elements are values of enumerable string-keyed properties found directly upon object. This is the same as iterating with a for...in loop, except that a for...in loop enumerates properties in the prototype chain as well.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › with
Array.prototype.with() - JavaScript | MDN
The with() method never produces a sparse array. If the source array is sparse, the empty slots will be replaced with undefined in the new array. The with() method is generic. It only expects the this value to have a length property and integer-keyed properties.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Indexed_collections
Indexed collections - JavaScript | MDN
An array is an ordered list of values that you refer to with a name and an index. For example, consider an array called emp, which contains employees' names indexed by their numerical employee number. So emp[0] would be employee number zero, emp[1] employee number one, and so on.
🌐
Eloquent JavaScript
eloquentjavascript.net › 04_data.html
Data Structures: Objects and Arrays :: Eloquent JavaScript
Most values in JavaScript have properties, with the exceptions being null and undefined. Properties are accessed using value.prop or value["prop"]. Objects tend to use names for their properties and store more or less a fixed set of them. Arrays, on the other hand, usually contain varying amounts of conceptually identical values and use numbers (starting from 0) as the names of their properties.