Canhua's Blog
  • Blogs
  • My GitHub Projects
  • Profile
  • Linkedin
Canhua's Blog

JavaScript tips - 2

December 25, 2021

swap element

const a = ['a', 'b', 'c', 'e', 'd'];
[a[3], a[4]] = [a[4], a[3]]; //[ 'a', 'b', 'c', 'd', 'e' ]
a=1, b=2;
[a, b]=[b, a];

Array push to append multiple values

array.push(element)

You can use a push() method to append more than one value to an array in a single call.

array.push(item1, item2, item3,...,itemN)

Profile picture

Written by Canhua Li Experienced Full Stack Engineer at Microsoft, proficient in C++, C#, JavaScript, React, AngularJS, Ruby & Rails, and .Net.

  • ← JavaScript Common Mistakes
  • Kid's word →
© 2023, Built with Gatsby