0

Working with Angular 5.

What I am trying to do is to assign in array a multidimensional array.

What is working with PHP?

$arM = array();
$arM["20/02/2020"][1] = ["name"=> 'my name', "id"=> 1];

the output of this is:

Array
(
    [20/02/2020] => Array
        (
            [1] => Array
                (
                    [name] => my name
                    [id] => 1
                )

        )

)

In angular when I am doing this is not working. Example:

let data:any = [];
data["20/02/2020"][1] = myArray;

How can I achieve the same result of PHP's?

Sujal Patel
  • 2,444
  • 1
  • 19
  • 38
Vasilis Greece
  • 861
  • 1
  • 18
  • 38
  • Please show how the expected output will look like – brk Feb 20 '20 at 13:58
  • Like php's result as shown above or in any similar form – Vasilis Greece Feb 20 '20 at 14:00
  • Does this answer your question? [How can I access and process nested objects, arrays or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – kvetis Feb 20 '20 at 14:05

2 Answers2

0

Like this maybe?

let data = {}; // Object (with keys), not array
data["20/02/2020"] = { name : "my name", id : 1 };

console.log(data);
Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
0
let data:Object = {
      "20/02/2020":[
         {"name":"my name", "id": 1}, 
         {"name":"my name2", "id": 2},
         {"name":"my name3", "id": 3}
      ]
 };