📜  Javascript index,length,push,pop,shift,unshift - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:45.179000             🧑  作者: Mango

代码示例1
var friends = ["Abrar", "Adil", "Adnan", "Alvi", "Ashraf"];
var friendsIndex = friends.indexOf("Alvi");
//Output:3
var friendsLength = friends.length;
//Output: 5
var friendsPositonChange = friends[3] = "Arif";
//Output: [ 'Abrar', 'Adil', 'Adnan', 'Arif', 'Ashraf' ]

var friendsPush = friends.push("Tahmina")
//Output:[ 'Abrar', 'Adil', 'Adnan','Arif', 'Ashraf', 'Tahmina' ]
var friendsPop = friends.pop();
//Output: [ 'Abrar', 'Adil', 'Adnan', 'Arif', 'Ashraf' ]

var friendsShift = friends.shift();
//Output: [ 'Adil', 'Adnan', 'Arif', 'Ashraf' ]

var friendsUnshift = friends.unshift("Shafi")
//Output: [ 'Shafi', 'Adil', 'Adnan', 'Arif', 'Ashraf' ]
console.log(friends)