DEV Community

Cover image for How to Access JavaScript Arrays in Objects
Asela
Asela

Posted on

How to Access JavaScript Arrays in Objects

Have an Object that contains an array, Then How to Access Arrays in Object,

Here is the simple Solution

Here's my Object

const myobj = {
"name":"John",
"age":30,
"cars":["Ford", "BMW", "Fiat"],
"PetName":"Dogee"
}
Enter fullscreen mode Exit fullscreen mode

Think if you need to access value in cars array. Just Code Like this

myobj.cars[value_index]
Enter fullscreen mode Exit fullscreen mode

So simple, isn't it? So Keep Following for tips like this.

Top comments (0)