2.9 KiB
2.9 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7b7e367417b2b2512b20 | Use an Array to Store a Collection of Data | 1 | 使用数组存储数据集合 |
Description
let simpleArray = ['one',2,'three',true,false,undefined,null];所有数组都有一个length属性,如上所示,可以使用语法
的console.log(simpleArray.length);
//记录7
Array.length
轻松访问Array.length
。下面可以看到更复杂的数组实现。这称为多维数组 ,或包含其他数组的数组。请注意,此数组还包含JavaScript 对象 ,我们将在下一节中详细介绍,但是现在,您需要知道的是,数组也能够存储复杂对象。 让complexArray = [
[
{
一:1,
二:2
},
{
三:3,
四:4
}
]
[
{
a:“a”,
b:“b”
},
{
c:“c”,
d:“d”
}
]
]。
Instructions
yourArray
的变量。通过为yourArray
变量指定长度至少为5个元素的数组来完成该语句。您的数组应至少包含一个字符串 ,一个数字和一个布尔值 。 Tests
tests:
- text: yourArray是一个数组
testString: 'assert.strictEqual(Array.isArray(yourArray), true, "yourArray is an array");'
- text: <code>yourArray</code>至少有5个元素
testString: 'assert.isAtLeast(yourArray.length, 5, "<code>yourArray</code> is at least 5 elements long");'
- text: <code>yourArray</code>至少包含一个<code>boolean</code>
testString: 'assert(yourArray.filter( el => typeof el === "boolean").length >= 1, "<code>yourArray</code> contains at least one <code>boolean</code>");'
- text: <code>yourArray</code>至少包含一个<code>number</code>
testString: 'assert(yourArray.filter( el => typeof el === "number").length >= 1, "<code>yourArray</code> contains at least one <code>number</code>");'
- text: <code>yourArray</code>至少包含一个<code>string</code>
testString: 'assert(yourArray.filter( el => typeof el === "string").length >= 1, "<code>yourArray</code> contains at least one <code>string</code>");'
Challenge Seed
let yourArray; // change this line
Solution
// solution required