Tag Archives forwebprogramming

Sort an array in javascript by property of one of the object elements

Say you have an array consisting of objects. And you want to order that array by one of the properties of these objects.

Take this array:

[
    {
        id: 4,
        title: "Lorem ipsum",
        created: "2020-04-10T14:59:00+00:00"
    },
    {
        id: 2,
        title: "Iptum quanto",
        created: "2020-05-29T13:17:48+00:00"
    },
    {
        id: 1,
        title: "Dolor samet",
        created: "2020-05-29T13:16:20+00:00"
    },
    {
        id: 3,
        title: "Tenari fluptum",
        created: "2020-05-29T13:08:39+00:00"
    }
]

Let’s sort it by the created property of each element

const orderedChapters = chapters.sort((a, b) => {
  return a.created.localeCompare(b.created))
}

This is the order now

[
  {
    id: 4,
    title: "Lorem ipsum",
    created: "2020-04-10T14:59:00+00:00"
  },
  {
    id: 3,
    title: "Tenari fluptum",
    created: "2020-05-29T13:08:39+00:00"
  },
  {
    id: 1,
    title: "Dolor samet",
    created: "2020-05-29T13:16:20+00:00"
  },
  {
    id: 2,
    title: "Iptum quanto",
    created: "2020-05-29T13:17:48+00:00"
  }
]

POST request turns into GET request

I was firing login request to my API but I could not get it to return the correct response.

Upon investigation, it turns out that the API received a GET request while I issued a POST request with Postman.

The issue? I was sending the POST request to http while the API was listening on https!

It turns out that the request was forwarded to the https address as a GET request…

Solution: send requests to the https address

>