// Array length shows how many elements exist in the array
let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']
let result = fruits.length;
console.log(result);
Array.toString()
// The JavaScript method toString() converts an array to a string of (comma separated) array values.
let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']
let result = fruits.toString();
console.log(result);
Array.at(index)
// at() returns the element at the specified index
let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']
let result = fruits.at(2);
console.log(result);
Array.join('whatever')
// join() joins the elements of an array into a string and joins with whatever we insert inside (join()) parentheses
let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
let result = fruits.join('-')
console.log(result); // => apple-banana-cherry-date-elderberry
Array.pop()
// pop() removes the last element from an array and returns that element
let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
let result = fruits.pop()
console.log(result); // => elderberry
console.log(fruits); // => ['apple', 'banana', 'cherry', 'date'];
Array.push()
// Array.push() adds from the end and shows the length
let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
let result = fruits.push('kiwi');
console.log(result); // => 6 ! returns the length
console.log(fruits); // => ['apple', 'banana', 'cherry', 'date', 'elderberry', 'kiwi']
Array.shift()
// shift() deletes from the beginning and returns the deleted element
let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
let result = fruits.shift();
console.log(result); // => apple
Array.unshift()
// unshift() adds from the beginning and returns the new length
let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
let result = fruits.unshift('pear');
console.log(result); // => apple
console.log(fruits); // => ['pear', 'apple', 'banana', 'cherry', 'date', 'elderberry']
delete array[index]
// delete leaves empty holes in the array therefore use push() or pop()
let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
delete fruits[1];
console.log(fruits); // => ['apple', empty, 'banana', 'cherry', 'date', 'elderberry']
concat()
// The concat() method creates a new array by merging (concatenating) existing arrays:
const myGirls = ["Cecilie", "Lone"];
const myBoys = ["Emil", "Tobias", "Linus"];
const myChildren = myGirls.concat(myBoys);
array.flat()
// The flat() method creates a new array with sub-array elements concatenated to a specified depth.
const myArr = [[1,2],[3,4],[5,6]];
const newArr = myArr.flat();
console.log(newArr); // => [1,2,3,4,5,6]
Heroku tackles the toil β patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.
Get inspired by experts at PulumiUP. Discover the latest in platform engineering, IaC, and DevOps. Keynote, demos, panel, and Q&A with Pulumi engineers.
Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.
A genuine "thank you" can truly uplift someoneβs day. Feel free to express your gratitude in the comments below!
On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.
Top comments (1)
π