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?

3
  • Please show how the expected output will look like Commented Feb 20, 2020 at 13:58
  • Like php's result as shown above or in any similar form Commented Feb 20, 2020 at 14:00
  • Does this answer your question? How can I access and process nested objects, arrays or JSON? Commented Feb 20, 2020 at 14:05

2 Answers 2

0

Like this maybe?

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

console.log(data);

Sign up to request clarification or add additional context in comments.

2 Comments

something like this but you missed the key of the object which I need to be 1 not 0.
What does that mean? Where did I set an object with a key "0" ?
0
let data:Object = {
      "20/02/2020":[
         {"name":"my name", "id": 1}, 
         {"name":"my name2", "id": 2},
         {"name":"my name3", "id": 3}
      ]
 };

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.