1

I have some JSON below. I plan on sorting all these values into arrays based on type. I won't know what the type value will be, but I want the following values to be sorted into different arrays based on type. This has to be in JavaScript. If I knew how to get started with this, I would include a code snippet of how I would get started with this, but I don't. I need help.

Original Value

[
   {
      "number":25,
      "type":"video/mp4",
      "url":"https://www.example.com/link/video/1"
   },
   {
      "number":67,
      "type":"video/mp4",
      "url":"https://www.example.com/link/video/2"
   },
   {
      "number":38,
      "type":"video/mp4",
      "url":"https://www.example.com/link/video/3"
   },
   {
      "number":56,
      "type":"video/webm",
      "url":"https://www.example.com/link/video/4"
   },
   {
      "number":14,
      "type":"video/mp4",
      "url":"https://www.example.com/link/video/5"
   },
   {
      "number":88,
      "type":"video/webm",
      "url":"https://www.example.com/link/video/6"
   },
   {
      "number":24,
      "type":"video/mp4",
      "url":"https://www.example.com/link/video/7"
   },
   {
      "number":44,
      "type":"video/webm",
      "url":"https://www.example.com/link/video/8"
   },
   {
      "number":62,
      "type":"video/mp4",
      "url":"https://www.example.com/link/video/9"
   },
   {
      "number":33,
      "type":"video/webm",
      "url":"https://www.example.com/link/video/10"
   },
   {
      "number":30,
      "type":"video/mp4",
      "url":"https://www.example.com/link/video/11"
   },
   {
      "number":89,
      "type":"video/webm",
      "url":"https://www.example.com/link/video/12"
   },
   {
      "number":24,
      "type":"video/mp4",
      "url":"https://www.example.com/link/video/13"
   },
   {
      "number":17,
      "type":"video/webm",
      "url":"https://www.example.com/link/video/14"
   },
   {
      "number":56,
      "type":"video/mp4",
      "url":"https://www.example.com/link/video/15"
   },
   {
      "number":64,
      "type":"video/webm",
      "url":"https://www.example.com/link/video/16"
   },
   {
      "number":73,
      "type":"audio/mp4",
      "url":"https://www.example.com/link/video/17"
   },
   {
      "number":30,
      "type":"audio/webm",
      "url":"https://www.example.com/link/video/18"
   },
   {
      "number":41,
      "type":"audio/webm",
      "url":"https://www.example.com/link/video/19"
   },
   {
      "number":36,
      "type":"audio/webm",
      "url":"https://www.example.com/link/video/20"
   }
]

Ideal Value

[
   [
      {
         "number":25,
         "type":"video/mp4",
         "url":"https://www.example.com/link/video/1"
      },
      {
         "number":67,
         "type":"video/mp4",
         "url":"https://www.example.com/link/video/2"
      },
      {
         "number":38,
         "type":"video/mp4",
         "url":"https://www.example.com/link/video/3"
      },
      {
         "number":14,
         "type":"video/mp4",
         "url":"https://www.example.com/link/video/5"
      },
      {
         "number":24,
         "type":"video/mp4",
         "url":"https://www.example.com/link/video/7"
      },
      {
         "number":62,
         "type":"video/mp4",
         "url":"https://www.example.com/link/video/9"
      },
      {
         "number":30,
         "type":"video/mp4",
         "url":"https://www.example.com/link/video/11"
      },
      {
         "number":24,
         "type":"video/mp4",
         "url":"https://www.example.com/link/video/13"
      },
      {
         "number":56,
         "type":"video/mp4",
         "url":"https://www.example.com/link/video/15"
      }
   ],
   [
      {
         "number":56,
         "type":"video/webm",
         "url":"https://www.example.com/link/video/4"
      },
      {
         "number":88,
         "type":"video/webm",
         "url":"https://www.example.com/link/video/6"
      },
      {
         "number":44,
         "type":"video/webm",
         "url":"https://www.example.com/link/video/8"
      },
      {
         "number":33,
         "type":"video/webm",
         "url":"https://www.example.com/link/video/10"
      },
      {
         "number":89,
         "type":"video/webm",
         "url":"https://www.example.com/link/video/12"
      },
      {
         "number":17,
         "type":"video/webm",
         "url":"https://www.example.com/link/video/14"
      },
      {
         "number":64,
         "type":"video/webm",
         "url":"https://www.example.com/link/video/16"
      }
   ],
   [
      {
         "number":73,
         "type":"audio/mp4",
         "url":"https://www.example.com/link/video/17"
      }
   ],
   [
      {
         "number":30,
         "type":"audio/webm",
         "url":"https://www.example.com/link/video/18"
      },
      {
         "number":41,
         "type":"audio/webm",
         "url":"https://www.example.com/link/video/19"
      },
      {
         "number":36,
         "type":"audio/webm",
         "url":"https://www.example.com/link/video/20"
      }
   ]
]
myjobistobehappy
  • 736
  • 5
  • 16
  • Welcome to Stack Overflow! Please read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) Your best bet here is to do your research, [search](/help/searching) for related topics on SO, and give it a go. ***If*** you get stuck and can't get unstuck after doing more research and searching, post a [mcve] of your attempt and say specifically where you're stuck. People will be glad to help. – T.J. Crowder Nov 26 '20 at 08:07
  • 1
    Side note: You almost certainly *don't* have "some JSON below." :-) JSON is a *textual notation* for data exchange. [(More here.)](http://stackoverflow.com/a/2904181/157247) If you're dealing with JavaScript source code, and not dealing with a *string*, you're not dealing with JSON. – T.J. Crowder Nov 26 '20 at 08:08
  • @T.J.Crowder, I know JavaScript and what JSON is. I just don't know how I can sort JSON to match what I need. I appreciate the response. – myjobistobehappy Nov 26 '20 at 08:14
  • 1
    _"I know JavaScript and what JSON is"_ - Then why are you still talking about _"how I can sort JSON"_? JSON is a string. Sorting a string doesn't make sense. What you have here is an array of objects. – Andreas Nov 26 '20 at 08:28
  • 1
    @myjobistobehappy - The previous comment was from Andreas, not me. You still don't seem to understand what JSON is, please read the answer I linked above. If you have `{"foo": "bar"}` in JavaScript source code, it's not JSON. If you read JSON from a file or network connection or similar, it's a **string**. When you parse that string using `JSON.parse`, the result is not JSON. It's the result of *parsing* JSON. JSON is *text* whose contents are in a particular format. You *parse* that text into values (including arrays). – T.J. Crowder Nov 26 '20 at 08:44

0 Answers0