JavaScript-3
JavaScript Arrays
Get Janujah Sivarattinam’s stories in your inbox
Join Medium for free to get updates from this writer.
It is a method of categorizing variables and attributes. Arrays can be Defined as a collection of object of the same type.
var car = ["Mercedes","Tesla","Volvo"]pop(): This method is used for removing the last element of an array.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.pop())
//Output
Volvo
push(): This method is used for adding a new element at the very end of an array.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.push())
//Output
3concat(): This method is used for joining various arrays into a single array.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.concat())
//Output
[ 'Mercedes', 'Tesla', 'Volvo' ]reverse(): This method is used for reversing the order of the elements in an array.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.reverse())
//Output
[ 'Volvo', 'Tesla', 'Mercedes' ]shift(): This method is used for removing the first element of an array.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.shift())
//Output
Mercedesslice(): This method is used for pulling a copy of a part of an array into a new array.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.slice(1)) // 1 is an index of the array
//Output
[ 'Tesla', 'Volvo' ]splice(): This method is used for adding elements in a particular way and position.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.splice(2)) // 2is an index of the array
//Output
[ 'Volvo' ]toString(): This method is used for converting the array elements into strings.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.tostring())
//Output
Mercedes,Tesla,Volvounshift(): This method is used for adding new elements at the beginning of the array.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.unshift())
//Output
3valueOf(): This method is used for returning the primitive value of the given object.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.valueOf())
//Output
[ 'Mercedes', 'Tesla', 'Volvo' ]indexOf(): This method is used for returning the first index at which a given element is found in an array.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.indexOf("Tesla"))
//Output
1lastIndexOf(): This method is used for returning the final index at which a given element appears in an array.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.lastIndexOf("Volvo"))
//Output
2join(): This method is used for combining elements of an array into one single string and then returning it.
var car = ["Mercedes","Tesla","Volvo"];
console.log(car.join("|"))
//Output
Mercedes|Tesla|Volvosort(): This method is used for sorting the array elements based on some condition.
var car = ["Susuki","Mercedes","Tesla","Volvo"];
console.log(car.sort())
//Output
[ 'Mercedes', 'Susuki', 'Tesla', 'Volvo' ]






