Я новичок в java, и мне не удается вызвать содержимое массива с конструктором. Я хочу конкретно называть содержимое в массив типа «omAttachment», «omText» и т.д.Array содержащий конструктор undefined js
здесь конструктор и массив:
function observeMessages(attachment, read, senderId, sent, text, type, userName){
this.omAttachment = attachment;
this.omRead = read;
this.omSenderId = senderId;
this.omSent = sent;
this.omText = text;
this.omType = type;
this.omUserName = userName;
}
var messageHistoryArray = [];
добавить застройщик так:
var newMessage = new observeMessages(obj.attachment, obj.read, obj.senderId, obj.sent, obj.text, obj.type, obj.userName);
messageHistoryArray.push(newMessage);
Когда я пытаюсь напечатать в консоли, он говорит, что не определено:
console.log(messageHistoryArray[0]); /in js file
Когда я печать л ike this in console (google chrome) я получаю следующее:
console.log(messageHistoryArray); //in js file
//print out in chrome console
Array[0]
0:observeMessages
omAttachment:false
omRead:"read"
omSenderId:"randomSenderId"
omSent:1479573310.904605
omText:"random text stuff"
omType:"type"
omUserName:"userName"
Я просто проверял свой код и он отлично работает! Даже в вашем примере это не печать неопределенной. – bman