let arr = [1, 2, 3];
arr.slice().reverse().forEach(x => console.log(x))
will print:
3
2
1
arr
will still be [1, 2, 3]
, the .slice()
creates a shallow copy.
More Related Contents:
- How to get the difference between two arrays of objects in JavaScript
- JavaScript: Difference between .forEach() and .map()
- How to extend an existing JavaScript array with another array, without creating a new array
- JavaScript: How to join / combine two arrays to concatenate into one array?
- Maximum size of an Array in Javascript
- Merge 2 arrays of objects
- Convert string with commas to array
- JavaScript, Node.js: is Array.forEach asynchronous?
- Completely removing duplicate items from an array
- How to remove element from an array in JavaScript?
- How to flatten nested array in javascript? [duplicate]
- sort Javascript array by two numeric fields
- Merge duplicate objects in array of objects
- Create object from array
- Comparing two arrays of objects, and exclude the elements who match values into new array in JS
- How to generate range of numbers from 0 to n in ES2015 only?
- Count duplicates within an Array of Objects
- Does .sort function change original array?
- How to convert hex string into a bytes array, and a bytes array in the hex string?
- How do I group items in an array by date?
- How can I perform an inner join with two object arrays in JavaScript?
- How to merge each object within arrays by index?
- Unexpected comma using map()
- Counting occurrences of particular property value in array of objects [duplicate]
- Javascript: Is the length method efficient?
- How to find a value in an array of objects in JavaScript?
- Filter nested array in object array by array of values
- Using jQuery inArray with array of JavaScript Objects
- best way to generate empty 2D array
- Access object property in array of objects