I'm new to Javascript and I would like to know how to make an associative array in JavaScript. I want to push my array in the main array to for an associative array. I know how to do it in PHP.
PHP equivalent:
$associativeArray = [
[
'name' => 'Bob',
'age' => '18',
'address' => '442 Grand Ave'
],
];
How can I do the same in Javascript?
Here is my code:
var mainArray = {};
var arr = [];
arr['name'] = 'Bob';
arr['age'] = '18';
arr['address'] = '442 Grand Ave';
arr.push(mainArr);
console.log(mainArr); // output: {}
arrvariable, and switch your push around tomainArr.push(arr).