I have a JS object where there is a attribute called value. After some kind of operation I am updating the value property of the object. Now I am facing a strange behavior as follow.
My code is like;
console.log(root.formElements[key][i]); <-------- Line 1
console.log(root.formElements[key][i]["value"]); <-------- Line 2
The lines of code is exactly one after another.
Now in chrome console I am getting the result as follow;
For Line 1
{name: "campaignStartDate", label: "Campaign Start Date", type: "date", mandatory: "yes", icon: "event_note", …}
class:"s4"
classField:"startDate"
icon:"event_note"
label:"Campaign Start Date"
mandatory:"yes"
name:"campaignStartDate"
newrow:"yes"
type:"date"
value:""
For Line 2
01/04/2018
So the question is how is it possible when I am printing the object the value is blank but in next line if I print is individually the I am getting the value?
The code snippet;
for (var key in root.formElements) {
for(var i=0;i<root.formElements[key].length;i++)
{
root.formElements[key][i]["value"] = data[root.formElements[key][i]["classField"]];
if(root.formElements[key][i]["name"] == "campaignStartDate")
{
console.log(root.formElements[key][i]);
console.log(root.formElements[key][i]["value"]);
}
}
FYI I am facing this issue when I am developing an Angular 4 application. And In my application also I am getting the value property of the object is blank, when I am expecting the date string there.
Any help will be very good for me. Please let me know if any more data is required.
Thanks in advance.