-1

I have a function which returns an array of objects like this

const allGreen = _.filter(
sidebarLinks,
side => !isServicePage(side.slug.current)

);

enter image description here

I'm trying to swap positions of these object.

  • The first object should be at the last position.
  • The second object should be the first one
  • The third object should be in the middle
Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
Eirik Vattøy
  • 175
  • 1
  • 14

1 Answers1

1

You are going to remove the first object, and place it at the last position:

const allGreen = _.filter(
  sidebarLinks,
  side => !isServicePage(side.slug.current)
);

allGreen.push(allGreen.shift());

The method shift of Array removes the first element, and returns it.

The method push adds one or more elements at the end of an array.

Nathan Xabedi
  • 1,097
  • 1
  • 11
  • 18