Created
March 29, 2021 17:50
-
-
Save vishalkukreja/3ad7139764b008700fdfddd3cc4ebf3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic array | |
var cityNames = ['Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore']; | |
console.log("City names:", cityNames); | |
// Output : City names: [ 'Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore' ] | |
console.log("City at 2nd index:", cityNames[2]); | |
//Add an item to an array | |
cityNames.push('Jaipur'); | |
console.log("City names:", cityNames); | |
//Output: City names: [ 'Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore', 'Jaipur' ] | |
//Remove an item from an array | |
cityNames.pop(); | |
console.log("City names:", cityNames); | |
//Output: City names: [ 'Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore' ] | |
//Remove an item from the beginning of an Array | |
cityNames.shift(); | |
console.log("City names:", cityNames); | |
//Output: City names: [ 'Delhi', 'Pune', 'Ahmadabad', 'Indore' ] | |
//Add an item to the beginning of an Array | |
cityNames.unshift('Chennai', 'Mumbai'); | |
console.log("City names:", cityNames); | |
//Output: City names: [ 'Chennai', 'Mumbai', 'Delhi', 'Pune', 'Ahmadabad', 'Indore' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment