Cannot read property "employee" from undefined

I try to set "*****" to employee_salary property 

this is my js code

var data = context.getVariable("data");
var jsonObject = JSON.parse(data);

for(var i = 1; i <= jsonObject.length; i++) {
print(jsonObject[i]) //[object Object]
print(jsonObject[i].employee_salary) 
jsonObject[i].employee_salary = "*****"; //undefined
}

this is my data from extracted variable

suchansinee_0-1673415913979.png

but I get response error \"TypeError: Cannot set property \"employee_salary\" of undefined to \"*******\".

this is log from print()

suchansinee_1-1673416224257.png

 

What is the problem? 

How can I resolve it?

Thank you.

@dchiesa1 

0 2 140
2 REPLIES 2

You're looping through an array.. however your for loop starts from i = 1, and goes until i <= array length.. This means you're starting from the second element, and then going beyond the bounds of your array

Thank you