Hey everyone i'm currently learning more about javascript and wanted to know how to do something like this in PHP which is a multidimensional array with key pairs
But how would i do something like this in javascript this is what i have attempted and so far only got errors i'm using an object rather than array if i'm going about this wrong please tell me haha
Why do you try to make an Object? In Object JS doing it other way(with ':' and ',')
Generate Key Javascript Map Array Example
May 28, 2019 This typescript tutorial explains TypeScript Map, how we can create a map in typescript, various map properties and methods. We will also discuss how to iterate over Map entries, Array map, clone and merge maps, merge map with an array, Convert Map Keys/Values to an Array, Weak Map, etc.
![Generate key javascript map array download Generate key javascript map array download](/uploads/1/2/5/8/125869745/115558152.png)
Butif you need a multidimensional array do this way:
Would i just access the variables in the array like
Hi Tunde,
Since an array is an object in javascript, would something like this suit you?
You can access each property either like this: multiarray.cat.name or if you prefer it to be like php: multiarray['cat']['legs']
Oh, I see! What you calling array is collection indeed. To access it like hotels['hilton']['name'] you need such object:
So, the solution to keep this data you need is:
Javascript Map Function
Your awesome haha sorry i thought it was called the same in js but thats exactly what i'm looking for are there any methods to add new items into the collection ?
Try to make it this way:
Awesome that works thanks for all your help mate :D
These are commonly known as Object Literals in JavaScript but yes they are indeed associative arrays since the indexes are named (with a string) and not a numeric index.
Posting to the forum is only allowed for members with active accounts.
Please sign in or sign up to post.
Please sign in or sign up to post.