### 【JS】重零學習- Day7-陣列

Js也有，一起下來觀看吧！

function(para1,para2,para3,para4,para5){
// Todo...
}/pre>


function(1,2,3,4,5);

## 首先介紹陣列

[1000,1300,3200,4400,5000,1000,5200]

...第七天5200 就可以用陣列表示

var salarys = [1000,1300,3200,4400,5000,1000,5200];

salary[0];

var weights=[78,76,75,77,77,78,75,80.....];

weights[2];

## 陣列的操控方法-新增

### 1.push

// 宣告薪水空陣列
var salarys = [];

// 新增一筆100
salarys.push(100);

// 目前薪水陣列有一筆,第一筆為100

// 新增一筆200
salarys.push(200);

// 目前薪水陣列有兩筆,第一筆為100,第二筆為200


### 2.splice

var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
var removed = myFish.splice(2, 0, 'drum');

// myFish 為 ["angel", "clown", "drum", "mandarin", "sturgeon"]
// removed 為 [], 沒有元素被刪除

## 陣列的操控方法-陣列長度

arrays.length
var salarys = [0,1,2,3,4,5,6,7];

// 算出你有幾筆資料
console.log(salarys.length);

// 結果為 8

## 陣列的操控方法-刪除

array.splice(start[, deleteCount[, item1[, item2[, ...]]]])
// splice(start,deleteCount)
// 語法:array.splice(start[, deleteCount[, item1[, item2[, ...]]]])

var chars = ['a', 'b', 'c', 'd'];
chars.splice(1, 0, 'e');
console.log(chars);

chars.splice(4, 1, 'f');
console.log(chars);

// Output:
// Array ["a", "e", "b", "c", "d"]
// Array ["a", "e", "b", "c", "f"]
var myFish = ['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon'];
var removed = myFish.splice(myFish.length - 3, 2);

// myFish 為 ["parrot", "anemone", "sturgeon"]
// removed 為 ["blue", "trumpet"]