Как получить полные значения в [Массив]? - PullRequest
1 голос
/ 06 мая 2020

у меня есть запрос POST с некоторыми данными, я отправляю с помощью Postman, такие данные, но у меня есть проблема, когда я console.log(newLesson) я не могу получить значение в [массиве], но когда я пытаюсь console.log(req.body.quizs) его можно !!! Кто-нибудь может мне объяснить, почему? И как я могу получить из этого ценность? Большое спасибо ?

    "name":"This is name",
    "videoId" : "this is videoId",
    "level" : "beginner",
    "script" : "this is Script",
    "quizs" : [
            {
                "question" : "This is question 1",
                "answer" : [
                        "Answer 1",
                        "Answer 2",
                        "Answer 3"
                    ],
                "correct_Answer" : "Answer 3"
            },
            {
                "question" : "This is question 2",
                "answer" : [
                        "Answer 1",
                        "Answer 2",
                        "Answer 3"
                    ],
                "correct_Answer" : "Answer 1"
            }
        ]
}

А это мой бэкэнд при получении

module.exports.addNewLesson = function(req,res){ 
    let newLesson = {
        name   : req.body.name,
        videoId  : req.body.videoId ,
        level  : req.body.level,
        script  : req.body.script,
        quizs : req.body.quizs
    };
    console.log(newLesson);
}

А вот что я получил

{
  name: 'This is name',
  videoId: 'this is videoId',
  level: 'beginner',
  script: 'this is Script',
  quizs: [
    {
      question: 'This is question 1',
      answer: [Array],
      correct_Answer: 'Answer 3'
    },
    {
      question: 'This is question 2',
      answer: [Array],
      correct_Answer: 'Answer 1'
    }
  ]
}

Как получить answer : [Array] ??? Спасибо

1 Ответ

0 голосов
/ 06 мая 2020

Попробуйте преобразовать вывод с форматированием:

console.log(JSON.stringify(newLesson, null, 4)); // 4 is the number of whitespaces used for formatting 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...