Loading

JavaScript Array Methods

JavaScript Array Methods

Hi friends, hope you all are safe and sound.

Today I am going to share some useful javascript array methods.

push():- push method appends given argument to an existing array. Example:

var Authors = ['Abhay','Sumanta','Soumya'];
Authors.push('Tarak');

console.log(Authors); // [ 'Abhay', 'Sumanta', 'Soumya', 'Tarak' ]

pop():- This method removes the last element from the array and return that removed element. Example

var Authors = ['Abhay','Sumanta','Soumya','Tarak'];
var newAuthors = Authors.pop();

console.log(newAuthors); // Tarak
console.log(Authors); //[ 'Abhay', 'Sumanta', 'Soumya' ]

toString():- This method converts array into string. Example

var Authors = ['Abhay','Sumanta','Soumya'];
var authorString = Authors.toString(); 

console.log(authorString ); // Abhay,Sumanta,Soumya

splice():- This method delete the item from the provided start location and append the provided element. this method returns the deleted items. Example

var Authors = ['Abhay','Sumanta','Soumya'];
var removedAuthors = Authors.splice(0,1,'Tarak'); 

console.log(removedAuthors); // ['Abhay']
console.log(Authors); //[ 'Tarak', 'Sumanta', 'Soumya' ]

reverse():- This method reverse array items as name describe itself. Example

var Authors = ['Abhay','Sumanta','Soumya','Tarak'];
Authors.reverse(); 

console.log(Authors); //[ 'Tarak', 'Soumya', 'Sumanta', 'Abhay' ]

Conclusion

This is a simple post about useful javascript method. I hope you like this article.

You may like this JavaScript Tips & Tricks

Related Articles