Osvaldas Valutis blog · Dec 24, 2023
Moving the first JavaScript array item to the end
0Sign in to vote or save
This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.
As an example for the use case, have you every ran into API’s which proudly feed you with week day based data, but ordered not in a way you expected, typically starting the week with Sunday, not Monday, or the other way around? const data = [ ` Sunday ` , ` Monday ` , ... , ` Saturday ` ] Well, there’s a single line cure for this: data . push ( data . shift ( ) ) Result: console . log ( data ) //…
Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.