Question: Is it possible to create an array and loop through it in JavaScript like below?

```
<?php
$options = array(
    'color' => array('blue', 'yellow', 'white'), 
    'size' => array('39', '40', '41'),
);

foreach($options as $option => $values){
    echo $option.'<br>';
    foreach($values as $value){
        echo $value.' ';
    }
    echo '<br>';
}
?>

```

I checked the internet but I can not find a good example.

Thanks for helping!

Answer: 
Exactly

```js
let options = {
    color: ['blue', 'yellow', 'white'],
    size: [39, 40, 41]
};

```

You have three ways to do this:

**FOR**

```js
for (option in options) {
    console.log(option);
    var values = options[option];
    for (let i = 0, len = values.length, value = values[i]; i < len; value = values[++i]) {
        console.log(value);
    }
}

```

**ARRAY FOREACH**

```js
for (option in options) {
    console.log(option);
    options[option].forEach(value => {
        console.log(value);
    });
}

```

*Easiest way:* **jQuery**

```js
$.each(options, (option, values) => {
    console.log(option);
    $.each(values, (key, value) => {
        console.log(value);
    });
});

```
If I understand you correctly you want a javascript equivalent to the php code you've given?

If so, it could be achieved the following way:

```js
let options = {
    color: ['blue', 'yellow', 'white'],
    size: [39, 40, 41]
};

for(option of Object.keys(options)) {
    console.log(option);

    for(value of options[option]) {
        console.log(value);
    }
}

```

this is not exactly the same as your php code, but the loop works in a similar way.