The splice() method always returns an Array

JavaScript for Beginners - Arrays: Adding and Removing Elements Part II - Working with the middle of a JavaScript array
0 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€60.11
List Price:  €85.87
You save:  €25.76
£52.07
List Price:  £74.39
You save:  £22.32
CA$96.72
List Price:  CA$138.18
You save:  CA$41.46
A$107.37
List Price:  A$153.39
You save:  A$46.02
S$90.24
List Price:  S$128.92
You save:  S$38.68
HK$545.84
List Price:  HK$779.80
You save:  HK$233.96
CHF 56.34
List Price:  CHF 80.49
You save:  CHF 24.15
NOK kr706.74
List Price:  NOK kr1,009.67
You save:  NOK kr302.93
DKK kr448.69
List Price:  DKK kr641.01
You save:  DKK kr192.32
NZ$119.45
List Price:  NZ$170.65
You save:  NZ$51.20
د.إ257.03
List Price:  د.إ367.21
You save:  د.إ110.17
৳8,511.37
List Price:  ৳12,159.63
You save:  ৳3,648.25
₹6,169.35
List Price:  ₹8,813.74
You save:  ₹2,644.38
RM295.88
List Price:  RM422.70
You save:  RM126.82
₦106,874.73
List Price:  ₦152,684.73
You save:  ₦45,810
₨19,719.68
List Price:  ₨28,172.18
You save:  ₨8,452.50
฿2,263.14
List Price:  ฿3,233.20
You save:  ฿970.05
₺2,881.58
List Price:  ₺4,116.73
You save:  ₺1,235.14
B$382.20
List Price:  B$546.03
You save:  B$163.82
R1,245.57
List Price:  R1,779.46
You save:  R533.89
Лв117.43
List Price:  Лв167.77
You save:  Лв50.33
₩97,558.65
List Price:  ₩139,375.48
You save:  ₩41,816.82
₪235.48
List Price:  ₪336.41
You save:  ₪100.93
₱3,998.15
List Price:  ₱5,711.89
You save:  ₱1,713.73
¥10,381.02
List Price:  ¥14,830.67
You save:  ¥4,449.64
MX$1,313.31
List Price:  MX$1,876.23
You save:  MX$562.92
QR254.80
List Price:  QR364.02
You save:  QR109.21
P939.68
List Price:  P1,342.46
You save:  P402.78
KSh9,042.70
List Price:  KSh12,918.70
You save:  KSh3,876
E£3,397.79
List Price:  E£4,854.20
You save:  E£1,456.40
ብር10,004.36
List Price:  ብር14,292.55
You save:  ብር4,288.19
Kz63,827.73
List Price:  Kz91,186.39
You save:  Kz27,358.65
CLP$67,779.01
List Price:  CLP$96,831.31
You save:  CLP$29,052.30
CN¥499.08
List Price:  CN¥713
You save:  CN¥213.92
RD$4,407.65
List Price:  RD$6,296.92
You save:  RD$1,889.26
DA9,093.02
List Price:  DA12,990.59
You save:  DA3,897.56
FJ$158.28
List Price:  FJ$226.12
You save:  FJ$67.84
Q536.13
List Price:  Q765.93
You save:  Q229.80
GY$14,622.96
List Price:  GY$20,890.84
You save:  GY$6,267.87
ISK kr8,633.26
List Price:  ISK kr12,333.76
You save:  ISK kr3,700.50
DH635.79
List Price:  DH908.31
You save:  DH272.52
L1,169.35
List Price:  L1,670.58
You save:  L501.22
ден3,693.98
List Price:  ден5,277.34
You save:  ден1,583.36
MOP$561.67
List Price:  MOP$802.43
You save:  MOP$240.75
N$1,232.98
List Price:  N$1,761.48
You save:  N$528.49
C$2,572.20
List Price:  C$3,674.73
You save:  C$1,102.52
रु9,857.19
List Price:  रु14,082.30
You save:  रु4,225.11
S/247.23
List Price:  S/353.21
You save:  S/105.97
K291.61
List Price:  K416.61
You save:  K124.99
SAR262.60
List Price:  SAR375.17
You save:  SAR112.56
ZK1,662.23
List Price:  ZK2,374.72
You save:  ZK712.48
L305.21
List Price:  L436.04
You save:  L130.82
Kč1,469.69
List Price:  Kč2,099.65
You save:  Kč629.95
Ft23,673.83
List Price:  Ft33,821.21
You save:  Ft10,147.37
SEK kr662.12
List Price:  SEK kr945.93
You save:  SEK kr283.80
ARS$95,260.79
List Price:  ARS$136,092.68
You save:  ARS$40,831.89
Bs482.98
List Price:  Bs690.01
You save:  Bs207.02
COP$280,278
List Price:  COP$400,414.31
You save:  COP$120,136.30
₡35,335.67
List Price:  ₡50,481.69
You save:  ₡15,146.02
L1,832.33
List Price:  L2,617.73
You save:  L785.40
₲504,830.94
List Price:  ₲721,217.97
You save:  ₲216,387.03
$U2,804.51
List Price:  $U4,006.62
You save:  $U1,202.10
zł255.72
List Price:  zł365.33
You save:  zł109.61
Already have an account? Log In

Transcript

One thing I'd like to point out very quickly is that the splice method always returns an array, regardless of what you pass to it. So for example, I've got this array here called foo with five elements. And if I call the splice method, it returns an empty array. And actually, if we inspect foo, we can say, we can see that it didn't do anything to foo. And that's because we didn't tell it what to do. So in a few seconds, we're going to start providing our the MR displace method, and it's going to start doing things to our array.

And it's going to return an array sometimes with things in it. But the main thing to keep in mind is that the splice method always returns an array. Always sometimes it's empty. Sometimes it has things in it. But that depends on what we pass to displace methods. So just it's an important thing to keep in mind because it can be confusing.

When you call splice and you tell it to remove one element, you think you're going to get that element back, but you don't you get an array with that element box. So the splice method always returns an array.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.