var array = [];
function object(name, username, password) {
return {
name: name,
user: username,
pwd: password,
}
}
var object1 = new object("jack", "jacky", "123")
var object2 = new object("bob", "bobby", "qwe")
array.push(object1, object2);
тогда или это:
var message = 'array'.concat(':', ' ', JSON.stringify(array, null, 2))
alert(message)
/*
array: [
{
"name": "jack",
"user": "jacky",
"pwd": "123",
},
{
"name": "bob",
"user": "bobby",
"pwd": "qwe",
}
]
*/
или это ...
array.forEach((arrayItem) => {
var message = 'object'.concat(':', ' ', JSON.stringify(arrayItem, null, 2))
alert(message)
})
/*
object: {
"name": "jack",
"user": "jacky",
"pwd": "123",
}
*/
/*
object: {
"name": "bob",
"user": "bobby",
"pwd": "qwe",
}
*/
или это ...
var message = array.reduce((_message, arrayItem) => {
var _objectMessage = 'object'.concat(':', ' ', JSON.stringfiy(arrayItem, null, 2), '\n')
_message = _message.concat(_objectMessage)
return _message
}, ''}
alert(message)
/*
object: {
"name": "jack",
"user": "jacky",
"pwd": "123",
}
object: {
"name": "bob",
"user": "bobby",
"pwd": "qwe",
}
*/