I've been reading up on javascript and I this site has helped me quite a lot. My goal is to create a javascript object with the "key, value" pair coming from variables. For starters I am trying to create the following javascript object, If I create like this:
var tester = {
person : "Sarah",
friends : ["Tom", "Nils"],
parents : ["Sandra", "Peter"]
};
That works fine. However trying a different approach:
var tester = {};
var person = "Sarah";
var friendsArr = ["Tom", "Nils"];
var parentsArr = ["Sandra", "Peter"];
tester[person] = person;
tester[friends] = friendsArr;
tester[parents] = parentsArr;
That doesn't work. What am I doing wrong?