Reputation: 39
My issue is with SCORES, when I console.log the entire object the scores part is somehow showing an extra set of brackets.
$(".submit").on("click", function() {
var newRoommate = {
"firstname": $('#first_name').val().trim(),
"lastname": $('#last_name').val().trim(),
"photo": $('#user_photo').val().trim(),
scores: [
$('#question_1').val(),
$('#question_2').val(),
$('#question_3').val(),
$('#question_4').val(),
$('#question_5').val(),
$('#question_6').val(),
$('#question_7').val(),
$('#question_8').val(),
$('#question_9').val(),
$('#question_10').val()
],
scoresInput
};
console.log(newRoommate); // .... scores[]: Array(10)
Why is it showing scores[]:?
Ideally, I want it to result in something like this when console.log.
{
firstname:"Ricky",
lastname:"Bobby",
photo:"http://www.topcelebsjackets.com/wp-content/uploads/2017/03/Talladega-Nights-Wonder-Bread-Ricky-Bobby-Jacket-6-570x708.jpg",
scores:[
5,
1,
4,
4,
5,
1,
2,
5,
4,
1
]
}
Upvotes: 1
Views: 474
Reputation: 8219
Chrome, Firefox, NodeJS, etc. will have different result for the same console.log
statement.
That is because console.log
is not a function delivered by JS, but actually an implementation delivered differently with each environment that JS is running on. If you'd take the raw JS (for example, Chrome V8) you'd notice that console
is not even defined (among others like document
or window
)
In your case, scores[]: Array(10)
is actually saying that you have a scores
key, which is an array, and has 10 elements.
Related: Throwing custom error doesn't preserve Error formatting in the log
Upvotes: 1