.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
access-array-data-with-indexes.chinese.md
access-multi-dimensional-arrays-with-indexes.chinese.md
accessing-nested-arrays.chinese.md
accessing-nested-objects.chinese.md
accessing-object-properties-with-bracket-notation.chinese.md
accessing-object-properties-with-dot-notation.chinese.md
accessing-object-properties-with-variables.chinese.md
add-new-properties-to-a-javascript-object.chinese.md
add-two-numbers-with-javascript.chinese.md
adding-a-default-option-in-switch-statements.chinese.md
appending-variables-to-strings.chinese.md
assignment-with-a-returned-value.chinese.md
build-javascript-objects.chinese.md
chaining-if-else-statements.chinese.md
comment-your-javascript-code.chinese.md
comparison-with-the-equality-operator.chinese.md
comparison-with-the-greater-than-operator.chinese.md
comparison-with-the-greater-than-or-equal-to-operator.chinese.md
comparison-with-the-inequality-operator.chinese.md
comparison-with-the-less-than-operator.chinese.md
comparison-with-the-less-than-or-equal-to-operator.chinese.md
comparison-with-the-strict-equality-operator.chinese.md
comparison-with-the-strict-inequality-operator.chinese.md
comparisons-with-the-logical-and-operator.chinese.md
comparisons-with-the-logical-or-operator.chinese.md
compound-assignment-with-augmented-addition.chinese.md
compound-assignment-with-augmented-division.chinese.md
compound-assignment-with-augmented-multiplication.chinese.md
compound-assignment-with-augmented-subtraction.chinese.md
concatenating-strings-with-plus-operator.chinese.md
concatenating-strings-with-the-plus-equals-operator.chinese.md
constructing-strings-with-variables.chinese.md
count-backwards-with-a-for-loop.chinese.md
counting-cards.chinese.md
create-decimal-numbers-with-javascript.chinese.md
declare-javascript-variables.chinese.md
declare-string-variables.chinese.md
decrement-a-number-with-javascript.chinese.md
delete-properties-from-a-javascript-object.chinese.md
divide-one-decimal-by-another-with-javascript.chinese.md
divide-one-number-by-another-with-javascript.chinese.md
escape-sequences-in-strings.chinese.md
escaping-literal-quotes-in-strings.chinese.md
find-the-length-of-a-string.chinese.md
finding-a-remainder-in-javascript.chinese.md
generate-random-fractions-with-javascript.chinese.md
generate-random-whole-numbers-with-javascript.chinese.md
generate-random-whole-numbers-within-a-range.chinese.md
global-scope-and-functions.chinese.md
global-vs.-local-scope-in-functions.chinese.md
golf-code.chinese.md
increment-a-number-with-javascript.chinese.md
initializing-variables-with-the-assignment-operator.chinese.md
introducing-else-if-statements.chinese.md
introducing-else-statements.chinese.md
iterate-odd-numbers-with-a-for-loop.chinese.md
iterate-through-an-array-with-a-for-loop.chinese.md
iterate-with-javascript-do...while-loops.chinese.md
iterate-with-javascript-for-loops.chinese.md
iterate-with-javascript-while-loops.chinese.md
local-scope-and-functions.chinese.md
logical-order-in-if-else-statements.chinese.md
manipulate-arrays-with-pop.chinese.md
manipulate-arrays-with-push.chinese.md
manipulate-arrays-with-shift.chinese.md
manipulate-arrays-with-unshift.chinese.md
manipulating-complex-objects.chinese.md
modify-array-data-with-indexes.chinese.md
multiple-identical-options-in-switch-statements.chinese.md
multiply-two-decimals-with-javascript.chinese.md
multiply-two-numbers-with-javascript.chinese.md
nest-one-array-within-another-array.chinese.md
nesting-for-loops.chinese.md
passing-values-to-functions-with-arguments.chinese.md
practice-comparing-different-values.chinese.md
profile-lookup.chinese.md
quoting-strings-with-single-quotes.chinese.md
record-collection.chinese.md
replacing-if-else-chains-with-switch.chinese.md
return-a-value-from-a-function-with-return.chinese.md
return-early-pattern-for-functions.chinese.md
returning-boolean-values-from-functions.chinese.md
selecting-from-many-options-with-switch-statements.chinese.md
shopping-list.chinese.md
stand-in-line.chinese.md
store-multiple-values-in-one-variable-using-javascript-arrays.chinese.md
storing-values-with-the-assignment-operator.chinese.md
subtract-one-number-from-another-with-javascript.chinese.md
testing-objects-for-properties.chinese.md
understand-string-immutability.chinese.md
understanding-boolean-values.chinese.md
understanding-case-sensitivity-in-variables.chinese.md
understanding-undefined-value-returned-from-a-function.chinese.md
understanding-uninitialized-variables.chinese.md
updating-object-properties.chinese.md
use-bracket-notation-to-find-the-first-character-in-a-string.chinese.md
use-bracket-notation-to-find-the-last-character-in-a-string.chinese.md
use-bracket-notation-to-find-the-nth-character-in-a-string.chinese.md
use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.chinese.md
use-conditional-logic-with-if-statements.chinese.md
use-multiple-conditional-ternary-operators.chinese.md
use-the-conditional-ternary-operator.chinese.md
use-the-parseint-function-with-a-radix.chinese.md
use-the-parseint-function.chinese.md
using-objects-for-lookups.chinese.md
word-blanks.chinese.md
write-reusable-javascript-with-functions.chinese.md
debugging
es6
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
english
portuguese
russian
spanish
schema
test
.babelrc
.editorconfig
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-translation.js
package-entry.js
package-lock.json
package.json
utils.js
docs
search-indexing
tools
utils
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.gitpod.yml
.node-inspectorrc
.prettierignore
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
LICENSE.md
README.md
SECURITY.md
change_volumes_owner.sh
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
lerna.json
package-lock.json
package.json
sample.env
68 lines
1.7 KiB
Markdown
68 lines
1.7 KiB
Markdown
![]() |
---
|
|||
|
id: 56bbb991ad1ed5201cd392ce
|
|||
|
title: Manipulate Arrays With unshift()
|
|||
|
challengeType: 1
|
|||
|
videoUrl: ''
|
|||
|
localeTitle: 使用unshift操作数组()
|
|||
|
---
|
|||
|
|
|||
|
## Description
|
|||
|
<section id="description">不仅可以<code>shift</code>元件关闭的阵列的开头的,也可以<code>unshift</code>元素添加到数组的开始,即在阵列的前添加元素。 <code>.unshift()</code>工作方式与<code>.push()</code>完全相同,但是不是在数组的末尾添加元素, <code>unshift()</code>会在数组的开头添加元素。 </section>
|
|||
|
|
|||
|
## Instructions
|
|||
|
<section id="instructions">使用<code>unshift()</code>将<code>["Paul",35]</code>添加到<code>myArray</code>变量的开头。 </section>
|
|||
|
|
|||
|
## Tests
|
|||
|
<section id='tests'>
|
|||
|
|
|||
|
```yml
|
|||
|
tests:
|
|||
|
- text: '<code>myArray</code>现在应该有[[“Paul”,35],[“dog”,3]]。'
|
|||
|
testString: 'assert((function(d){if(typeof d[0] === "object" && d[0][0] == "Paul" && d[0][1] === 35 && d[1][0] != undefined && d[1][0] == "dog" && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray), "<code>myArray</code> should now have [["Paul", 35], ["dog", 3]].");'
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
</section>
|
|||
|
|
|||
|
## Challenge Seed
|
|||
|
<section id='challengeSeed'>
|
|||
|
|
|||
|
<div id='js-seed'>
|
|||
|
|
|||
|
```js
|
|||
|
// Example
|
|||
|
var ourArray = ["Stimpson", "J", "cat"];
|
|||
|
ourArray.shift(); // ourArray now equals ["J", "cat"]
|
|||
|
ourArray.unshift("Happy");
|
|||
|
// ourArray now equals ["Happy", "J", "cat"]
|
|||
|
|
|||
|
// Setup
|
|||
|
var myArray = [["John", 23], ["dog", 3]];
|
|||
|
myArray.shift();
|
|||
|
|
|||
|
// Only change code below this line.
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
### After Test
|
|||
|
<div id='js-teardown'>
|
|||
|
|
|||
|
```js
|
|||
|
console.info('after the test');
|
|||
|
```
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
</section>
|
|||
|
|
|||
|
## Solution
|
|||
|
<section id='solution'>
|
|||
|
|
|||
|
```js
|
|||
|
// solution required
|
|||
|
```
|
|||
|
</section>
|