Skip to content

Instantly share code, notes, and snippets.

@mulderu
Created September 10, 2019 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mulderu/65dc5be3f1f8452a44fb9ab51ea3c110 to your computer and use it in GitHub Desktop.
Save mulderu/65dc5be3f1f8452a44fb9ab51ea3c110 to your computer and use it in GitHub Desktop.
javascript array basic 01

array operation : pop, push, shift, unshift, slice, splice

> a=[1,2,3,4,5,6,7]
[ 1, 2, 3, 4, 5, 6, 7 ]
> a.pop()
7
> a
[ 1, 2, 3, 4, 5, 6 ]
> a.shift()
1
> a
[ 2, 3, 4, 5, 6 ]
> a.unshift(1)
6
> a
[ 1, 2, 3, 4, 5, 6 ]
> a.push(7)
7
> a
[ 1, 2, 3, 4, 5, 6, 7 ]
> a.slice(2,4)
[ 3, 4 ]
> a
[ 1, 2, 3, 4, 5, 6, 7 ]
> a.splice(2,4)
[ 3, 4, 5, 6 ]
> a
[ 1, 2, 7 ]
> a.splice(2,0,[3,4,5,6])
[]
> a
[ 1, 2, [ 3, 4, 5, 6 ], 7 ]
> a.splice(2,1)
[ [ 3, 4, 5, 6 ] ]
> a
[ 1, 2, 7 ]
> a.splice(2,0,3)
[]
> a
[ 1, 2, 3, 7 ]
> a.splice(3,0,4)
[]
> a
[ 1, 2, 3, 4, 7 ]
> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment