-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
  • 24,410
  • 6
  • 32
  • 55
Eirik Vattøy
  • 155
  • 1
  • 11

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,077
  • 1
  • 10
  • 18