I've been struggling to create a specific data structure in Javascript and I could really use some guidance:
[arrayValue: {objectKey: objectValue}, arrayValue2: {objectKey: objectValue}]
Here's what I've attempted so far:
var arr = [];
var obj = {};
var name = "Test";
var password = 'password';
var value = 'value'
obj[name] = {name: name, value: value, password: password};
arr.push(obj);
I'm using this method of pushing data to an array because I have a dataset that requires multiple iterations.
Unfortunately, the results are not as expected:
[{"Test":{"name":"Test","value":"value","password":"password"}}, {"Test2":{"name":"Test","value":"value","password":"password"}}]
My intended format is:
["Test":{"name":"Test","value":"value","password":"password"}, "Test2":{"name":"Test","value":"value","password":"password"}]
This way, I can access array objects by their names like arr[Test].name
instead of arr[0].name
Any help on this would be greatly appreciated. Thank you!