我有一个看起来像数组的对象
var questions =
[ { started_time: 2017-05-04T12:46:39.439Z,
word: 'bottle',
questionId: '161013bd-00cc-4ad1-8f98-1a8384e202c8' },
{ started_time: 2017-05-04T12:47:26.130Z,
word: 'play',
questionId: 'a84bd1b4-8b9c-4ec7-862d-ba994ac1f371' },
{ started_time: 2017-05-04T12:47:50.156Z,
word: 'bottle',
questionId: '4c7e1ee8-651e-4086-8e69-ce64414a815a' },
{ started_time: 2017-05-04T12:54:40.703Z,
word: 'was',
questionId: '79412420-eee9-47e0-8fb8-d854c5889765' },
{ started_time: 2017-05-04T12:55:36.474Z,
word: 'liked',
questionId: '525d90c9-4cca-433c-99c5-56bb54756b9c' } ]
我试图创建一个像这样的单词数组:
["bottle", "play", "was", "liked"]
当我尝试使用questions.map(等等)时,我得到了
TypeError: questions.map is not a function
和Array.isArray(questions)为false
我无法弄清楚为什么我不能将其视为数组。任何帮助将不胜感激。
答案 0 :(得分:-1)
var question = [
{
started_time: '2017-05-04T12:46:39.439Z',
word: 'bottle',
questionId: '161013bd-00cc-4ad1-8f98-1a8384e202c8'
},
{
started_time: `2017-05-04T12:47:26.130Z`,
word: 'play',
questionId: 'a84bd1b4-8b9c-4ec7-862d-ba994ac1f371'
}
];
//console.log(JSON.stringify(question) + "<br>");
var result = question.map(function(x){
return x.word;
});
console.log(result);