0

I'm getting values from another application and (push)ing those values into an Array. Then I'm using that array to populate values in HTML dynamically. It's hard to explain the problem but here I go...

The only part of this that might be the problem is the "push". I won't put all the code in but here's the idea:

const activities = new Array();

(OTHER CODE FOR obj[I] HERE)

obj = accountTasks.data;
        for (var i = 0; i < obj.length; i++){

                    var activityId = (obj[i].id);
                    var activityOwner = (obj[i].Owner.name);
                    start = (obj[i].Created_Time)
                    startDate = new Date(start);
                    activityDate = startDate.toLocaleString();
                    activityLink = "";
                    activityLogo = "https://hello/ultraviolet/344/create-new.png";
                    activityTitle = (obj[i].Note_Title);
                    Content = (obj[i].Note_Content);
                    //activityDesc = (Content.replace(/crm.*crm/,g, ''));
                    activityDesc = (Content.replace(/[^,]crm*,|,[^,]*crm -/g, ''));

        activities.push({activityOwner,activityDate,activityLink,activityLogo,activityTitle,activityDesc});
        }

const html = activities.map(obj => {
            let item = document.querySelector('#template').innerHTML;
            item = item.replace('{date}', obj.activityDate);
            item = item.replace('{link}', obj.activityLink);
            item = item.replace('{title}', obj.activityTitle);
            item = item.replace('{owner}', obj.activityOwner);
            item = item.replace('{desc}', obj.activityDesc);
            item = item.replace('{logo}', obj.activityLogo);
            return item;
            });
            
            document.querySelector('#list').innerHTML = html.join('');  

That does not work. BUT if I console.log(activities) my file looks like this: (Which is what I would expect)

[
    {
        "activityOwner": "Raymond Carlson",
        "activityDate": "1/31/2022, 6:16:06 AM",
        "activityLink": "",
        "activityLogo": "https://hello/ultraviolet/344/create-new.png",
        "activityTitle": "Website Feedback",
        "activityDesc": "Mitsue told us how much she liked the ease of use of our website"
    },
    {
        "activityOwner": "Raymond Carlson",
        "activityDate": "4/15/2022, 4:00:00 PM",
        "activityLink": "https://hello/tab/Events/5200926000003301004",
        "activityLogo": "https://img.icons8.com/ultraviolet/344/overtime.png",
        "activityDesc": null
    }
]

Now the confusing part: If I take the contents of "activities" and declare activities that way, it works.

    activities = [
  {
        "activityOwner": "Raymond Carlson",
        "activityDate": "1/31/2022, 6:16:06 AM",
        "activityLink": "",
        "activityLogo": "https://hello/ultraviolet/344/create-new.png",
        "activityTitle": "Website Feedback",
        "activityDesc": "Mitsue told us how much she liked the ease of use of our website"
    },
    {
        "activityOwner": "Raymond Carlson",
        "activityDate": "4/15/2022, 4:00:00 PM",
        "activityLink": "https://hello/tab/Events/5200926000003301004",
        "activityLogo": "https://img.icons8.com/ultraviolet/344/overtime.png",
        "activityDesc": null
    }
]

When I check the console for the first example (push to activities) Push to activities

And the image for activities where I declared it literally

activities added literally

Sorry that went on and on. My actual question is: How can I modify my "push" statement (or something else) to get the same format of the second image? Especially since to me, they both appear the same.

Thank you!!

  • 1
    [console.log() shows the changed value of a variable before the value actually changes](https://stackoverflow.com/q/11284663) – VLAZ Nov 17 '22 at 14:36
  • Thank you, VLAZ. I feel a bit silly typing that long question just to find out I wasn't troubleshooting correctly. I was able to fix my problem in just a couple minutes thanks to this Appreciate it! – Nathan Zoho Nov 17 '22 at 15:16

0 Answers0