在下面的例子中,我想提取" apple"," orange"和" kiwi"立刻,并在控制台中显示它们。我不确定如何撰写subscript
。
arrayExample[0 && 1 && 2]
答案 0 :(得分:1)
您希望将数组的元素附加到字符串中。
在Javascript中,您可以使用+
运算符追加字符串(并且您的数组元素是字符串)。
有些事情:
console.log(arrayExample[0] + " " + arrayExample[1] + " " + arrayExample[2]);
答案 1 :(得分:1)
Array.prototype.slice
正是您要找的。 p>
arrayExample = ["apple", "orange", "kiwi", "banana", "melon", "peach"];
console.log(arrayExample.slice(0, 3));
查看docs。
BTW 0 && 1 && 2 === 0
; - )