[英]Javascript Concatenate array string
I'm kinda stuck in exercise for a couple of time, and I feel a little dumb because it seems quite easy lol.我有点坚持锻炼了一段时间,我觉得有点愚蠢,因为它看起来很容易哈哈。 Here's all the data:
这是所有数据:
Print the first element of the Vesper Martini array along with the string 'The first ingredient is: '
打印 Vesper Martini 数组的第一个元素以及字符串“第一个成分是:”
What I did so far: (the first line was already made)到目前为止我做了什么:(第一行已经完成)
var vesperMartini = ['Gordons', 'vodka', 'Kina Lillet', 'ice', 'lemon peel']; console.log ('The first ingredient is:'+ vesperMartini[1]);
The output: output:
Output >>>>Code is incorrect Did you concatenate the string as required? The output should start with The first ingredient is: The first ingredient is:vodka
I would be really glad if someone could help me.如果有人可以帮助我,我会非常高兴。 Thank you very much.
非常感谢。
The array index of most of the programming languages starts at 0
.大多数编程语言的数组索引从
0
开始。 So you have to try the 0
index.所以你必须尝试
0
索引。
var vesperMartini = ['Gordons', 'vodka', 'Kina Lillet', 'ice', 'lemon peel'];
console.log ('The first ingredient is:'+ vesperMartini[0]);
Arrays start at index 0, not 1. vesperMartini[0]
should do the trick. Arrays 从索引 0 开始,而不是
vesperMartini[0]
应该可以解决问题。
For reference, this is known as zero-based numbering .作为参考,这称为从零开始的编号。
In JS index is counted from 0 not from 1, first element of any array has index 0在 JS 中,索引从 0 开始计数,而不是从 1 开始,任何数组的第一个元素都有索引 0
console.log ('The first ingredient is:'+ vesperMartini[0]); console.log('第一个成分是:'+ vesperMartini[0]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.