Fix for replacing the middle item in an Array
the provided code `styles[(styles.length - 1) / 2] = "Classics";` will replace the last item instead of the middle one. in order to fix that we need to change code like this : `styles[Math.floor((styles.length - 1) / 2)] = "Classics";`
This commit is contained in:
parent
cceb7cbcc8
commit
70d1d874f6
1 changed files with 1 additions and 1 deletions
|
@ -3,7 +3,7 @@
|
|||
```js run
|
||||
let styles = ["Jazz", "Blues"];
|
||||
styles.push("Rock-n-Roll");
|
||||
styles[(styles.length + 1) / 2] = "Classics";
|
||||
styles[Math.floor((styles.length - 1) / 2)] = "Classics";
|
||||
alert( styles.shift() );
|
||||
styles.unshift("Rap", "Reggie");
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue