.github
api-server
client
config
curriculum
docs
guide
arabic
chinese
english
3d
accessibility
agile
algorithms
android-development
angular
apache
aspnet
bash
blender
blockchain
bootstrap
bsd-os
bulma
c
canvas
certifications
apis-and-microservices
coding-interview-prep
data-visualization
front-end-libraries
information-security-and-quality-assurance
javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
-iterate-through-the-keys-of-an-object-with-a-for...in-statement
access-an-arrays-contents-using-bracket-notation
access-property-names-with-bracket-notation
add-items-to-an-array-with-push-and-unshift
add-items-using-splice
index.md
add-key-value-pairs-to-javascript-objects
check-for-the-presence-of-an-element-with-indexof
check-if-an-object-has-a-property
combine-arrays-with-the-spread-operator
copy-an-array-with-the-spread-operator
copy-array-items-using-slice
create-complex-multi-dimensional-arrays
generate-an-array-of-all-object-keys-with-object.keys
iterate-through-all-an-arrays-items-using-for-loops
modify-an-array-stored-in-an-object
modify-an-object-nested-within-an-object
remove-items-from-an-array-with-pop-and-shift
remove-items-using-splice
use-an-array-to-store-a-collection-of-data
use-the-delete-keyword-to-remove-object-properties
index.md
basic-javascript
debugging
es6
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
index.md
responsive-web-design
index.md
chef
clojure
cloud-development
codeigniter
computational-genomics
computer-hardware
computer-science
containers
cplusplus
csharp
css
d3
data-science-tools
design-patterns
designer-tools
developer-ethics
developer-tools
devops
dns
docker
documentation
drupal
electron
elixir
elm
erlang
fsharp
game-development
gatsbyjs
git
go
graphql
groovy
haskell
haxe
hibernate
html
ionic
java
javascript
joomla
jquery
julia
kotlin
laravel
linux
logic
machine-learning
mariadb
mathematics
meta
miscellaneous
mobile-app-development
mongodb
natural-language-processing
neovim
network-engineering
nginx
nodejs
optical-alignment
php
powershell
product-design
progressive-web-apps
puppet
python
r
raspberry-pi
react
react-native
redux
rest-api
robotics
rt-os
ruby
rust
sass
security
semantic-ui
software-engineering
sql
ssh
svg
svn
swift
terminal-commandline
tomcat
tools
typescript
typography
user-experience-design
user-experience-research
vagrant
vim
virtualbox
visual-design
voice
vue
vue-cli
web-augmented-reality
web-components
web-performance
web-virtual-reality
wordpress
working-in-tech
xml
portuguese
russian
spanish
mock-guide
tools
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.french.md
README.italian.md
README.md
docker-compose-shared.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env
30 lines
1023 B
Markdown
30 lines
1023 B
Markdown
![]() |
---
|
||
|
title: Add Items Using splice()
|
||
|
---
|
||
|
## Add Items Using splice()
|
||
|
- Using the splice() function, you must remove the first 2 elements from array `arr` and replace them with `DarkSalmon` and `BlanchedAlmond`.
|
||
|
- Remember the splice function can take up to three parameters.
|
||
|
## Example:
|
||
|
```javascript
|
||
|
arr.splice(0, 1, "Two");
|
||
|
/* The first two paramemters are the same as they were in the previous challenge.
|
||
|
`0` will start the `splice()` function off at index 0.
|
||
|
The second parameter `1` will remove only 1 variable from the array.
|
||
|
The final variable "Two" will replace the variable in arr[0].
|
||
|
Note: The final parameter can take more than 1 arguement.
|
||
|
*/
|
||
|
```
|
||
|
|
||
|
## Solution:
|
||
|
```javascript
|
||
|
function htmlColorNames(arr) {
|
||
|
// change code below this line
|
||
|
arr.splice(0, 2, "DarkSalmon", "BlanchedAlmond");
|
||
|
// change code above this line
|
||
|
return arr;
|
||
|
}
|
||
|
|
||
|
// do not change code below this line
|
||
|
console.log(htmlColorNames(['DarkGoldenRod', 'WhiteSmoke', 'LavenderBlush', 'PaleTurqoise', 'FireBrick']));
|
||
|
```
|