Hi I need some help with javascript.
function PricingData(id,method,freq,service,price) {
this.ID=id;
this.PaymentMethod_ID=method;
this.PaymentFrequency_ID=freq;
this.Service_ID=service;
this.Price=price;
}
I need to create an array in this way.
var temp=new PricingData[]{new PricingData(1,2,3,4,5),new PricingData(1,2,3,4,5)};
but this doesn't work. I'm going to pass the data in through the server so I would prefer syntax similar to this
To convert an object to an array you use one of three methods: Object. keys() , Object. values() , and Object. entries() .
JavaScript variables can be objects. Arrays are special kinds of objects. Because of this, you can have variables of different types in the same Array.
{} is shorthand for creating an empty object. You can consider this as the base for other object types. Object provides the last link in the prototype chain that can be used by all other objects, such as an Array . [] is shorthand for creating an empty array.
Use array literal notation to create an array:
var tmp = [new PricingData(1,2,3,4,5), new PricingData(1,2,3,4,5)];
For more information about arrays have a look at MDC - Array.
just put the new object right between the square brakcets
var arr = [new whatever(), new whatever()];
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