Reputation: 21
I want to know if it is possible to declare an array in Javascript of the type "com.peregrine.servicecenter.PWS.Common.MessageType". In java it is easy but in javascript I have not idea. Thanks.
Upvotes: 2
Views: 4329
Reputation: 3997
You can declare the array in such a way.
var arr = [];
it can contain object or array of object by calling
arr.push(x)
Reference
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array
Upvotes: 0
Reputation: 7663
You cannot declare an array to exclusively consist of a particular type. However, you can declare an array (var myArray = [];
) and you can add objects of your intended type to it (myArray.push(myMessageType);
).
Upvotes: 0
Reputation: 81988
No, it is not possible. The Array in JS doesn't care what you've put in it, or even that the array indexes are numeric. Java, on the other hand, requires strict typing of both. I'd even go so far as to say that even Object[]
is a completely different paradigm from []
.
Upvotes: 0
Reputation: 6814
sure it's possible:
var myArray = [];
remember that javascript is not a statically typed language, so you don't need to declare an array of a specific type.... just an array. Now, given the type you're referring to, I don't think that's exactly what you're asking though...
Upvotes: 2