freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../basic-javascript/access-multi-dimensional-ar...

2.0 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
56592a60ddddeae28f7aa8e1 Access Multi-Dimensional Arrays With Indexes 1 访问带索引的多维数组

Description

考虑多维数组的一种方法是作为数组的数组 。使用括号访问数组时,第一组括号引用最外层(第一级)数组中的条目,另外一对括号引用内部的下一级条目。
var arr = [
[1,2,3]
[4,5,6]
[7,8,9]
[[10,11,12]13,14]
]。
ARR [3]; //等于[[10,11,12]13,14]
ARR [3] [0]; //等于[10,11,12]
ARR [3] [0] [1]; //等于11
注意
数组名称和方括号之间不应该有任何空格,如array [0][0] ,甚至不允许使用此array [0] [0] 。尽管JavaScript能够正确处理但这可能会让其他程序员在阅读代码时感到困惑。

Instructions

使用括号表示法从myArray选择一个元素,使myData等于8

Tests

tests:
  - text: <code>myData</code>应该等于<code>8</code> 。
    testString: 'assert(myData === 8, "<code>myData</code> should be equal to <code>8</code>.");'
  - text: 您应该使用括号表示法从<code>myArray</code>读取正确的值。
    testString: 'assert(/myArray\[2\]\[1\]/g.test(code) && !/myData\s*=\s*(?:.*[-+*/%]|\d)/g.test(code), "You should be using bracket notation to read the correct value from <code>myArray</code>.");'

Challenge Seed

// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];

After Test

console.info('after the test');

Solution

// solution required