Skip to content

Instantly share code, notes, and snippets.

@pradeeprjth
Created August 18, 2021 06:13
Show Gist options
  • Save pradeeprjth/aef8765f476a7a3924e08e2fa1e2452a to your computer and use it in GitHub Desktop.
Save pradeeprjth/aef8765f476a7a3924e08e2fa1e2452a to your computer and use it in GitHub Desktop.
console.clear()
var mFriends = ['Shaw', 'Clara', 'Vab', 'Kun', 'Jacob', 'Dina']
mFriends.splice(3, 0, 'Donna', 'Rachel')
// 1st tells where to start
// 2nd tells how many items to be deleted
// 3rd and 4th and so on tells what items to be added
console.log(mFriends)
mFriends.splice(0, 0, 'Harvey')
console.log(mFriends)
// Delete item at specific position
mFriends.splice(2, 1)
console.log(mFriends)
mFriends.splice(0, 2)
console.log(mFriends)
// Concatenation
var mOfficeFriends = ['Nina', 'Aron', 'Katie', 'Vic', 'Paula']
var mAllFriends = mFriends.concat(mOfficeFriends)
console.log('====================================')
console.log(mFriends)
console.log(mOfficeFriends)
console.log(mAllFriends)
//Sorting Ascending and Descending
mAllFriends.sort()
console.log(mAllFriends)
mAllFriends.reverse()
console.log(mAllFriends)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment