var employee =
{
Column1: null,
Column2: null,
create: function () {
var obj = new Object();
obj.Column1 = "";
obj.Column2 = "";
return obj;
}
};
In C# I would do something like this:
List<Employee> employees = new List<Employee>();
for (int i = 0; i < 10; i++)
{
Employee emp = new Employee()
{
Column1 = "column 1 of emp" + i;
Column2 = "column 2 of emp" + i;
}
employees.Add(emp);
}
I need to do the same in javascript.
Pretty straight forward approach to creating an array of objects.
var employees = [];
for (var i = 0; i < 10; i++) {
employees.push({
Column1: 'column 1 of emp' + i,
Column2: 'column 1 of emp' + i
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With