Today, we’re going to look at how to reorder an item in an array.
This article comes from a question asked by one of my students, Sam Hibberd (shared with permission).
Has anyone got a robust helper for moving an item in an array from one index to another?
Let’s dig in.
An example Let’s say you had an array of delicious sandwiches.
var sandwiches = [‘ham’, 'tuna’, 'turkey’, 'pb&j’]; You want to change the order of the array so that turkey is in the first spot.