Array

  • Array Prototype

Determine the number of items in the array: arrayName.length example1 / example2
Determine if an object is an Array: Array.isArray(“arrayName”) isArray() Function / instanceof
Returns an array as a comma separated string: arrayName.toString() example
Converts an array to a primitive value: arrayName.valueOf() example
Join the elements into a string with separator: arrayName.join() / arrayName.join(“, “) example
Add an element on the end: arrayName.push(“…”) / arrayName[arrayName.length]= “…” example1 / example2
Remove the last element: arrayName.pop() example1 / example2
Add an element on the beginning: arrayName.unshift(“…”) example
Remove the first element: arrayName.shift() example
Delete array elements: delete arrayName[index] example
Add anywhere on the array: arrayName.splice(index where new item is added, 0, “new item”) example
Remove: arrayName.splice (index of item to be removed, # of items to be removed) example
Create a merged array: newArray = array1.concat(array2, array3, …) example1 / example2
Copies out a part of an array into a new array: arrayName.slice(index of the 1st item to be removed, index of last item not included) example / example1 / example2 / example3 /
Sort arrays elements: arrayName.sort() / arrayName.sort(function) Numeric Sort / Random Number / Find Highest Number / Find Lowest Number / Object Array by Number / Object Array By Letter
Reverse the order of the elements: arrayName.reverse() example
Create new array from an arrays: arrayName.map(function) example
Reduce Array into 1 value: arrayName.reduce(function)
Create an array with all elements that passed the function: arrayName.filter(function) example
Split a string into an array: stringName.split(” “)

Array Functions: examples

Calls a function for each array element: arrayName.forEach() example

Checks if every element in an array pass a test: arrayName.every() example

Checks if any of the elements in an array pass a test: arrayName.some() example

Fill the elements with a static value: arrayName.fill() example
Returns the value of the first element in an array that pass a test: arrayName.find() example

Search for an element and returns its position: arrayName.indexOf() example

Returns the index of the first element that pass a test: arrayName.findIndex()  example

Search for an element, starting at the end, and returns its position: arrayName.lastIndexOf() example

Reduce the array to a single value going left-to-right: arrayName.reduce() example

Reduce the array to a single value going right-to-left: arrayName.reduceRight() example

Print Array Elements: for & while loop

Empty an Array: arr.length

Select Elements from an Array: slice()

Get the last element: arr[arr.length – 1]

Add an element to an Array: function()

Delete an element to an Array: function()

Array Function: example / map() / map() loop / map() Iteration

Returned Function: varName();

Immediately-invoked Function: functionName(p)();

Add an element to an Array, Sort then find Index: code1 / code2

Count Strings in Array: function()

Filter / Remove given values from Array: splice() / code1 / code2

Remove Falsy Values: filter() / code 2

Count Even Number Elements: for/if-else

Find the Difference of 2 Arrays: indexOf()

Get Sum of all the Numbers in Range: for loop

Shuffle Array: sort()

Print Multi-Dimensional Array: for loop

Split an Array into Multi-Dimensional Array: for loop / splice()

Return an Array of all Objects with Matching Property and Value Pairs: code

Find the Largest Number in a Multi-Dimensional Array: for loop / forEach()

Array of Country Names: https://css-tricks.com/snippets/javascript/array-of-country-names/

  • Create a list of Boulevards in Paris that contain ‘de’ anywhere in the name
    //https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris

var category = document.querySelector(‘.mw-category’),
links = Array.from(category.querySelectorAll(‘a’)),
de = links.map(link => link.textContent).filter(streetName => streetName.includes(‘de’));

Advertisements

About bernadetteengleman

Hello, I am Bernadette from New York City. I moved here from Chicago in 2013. I am originally from the Philippines. I started studying web programming in 2015. I love it because I like making fun websites and web apps. The projects that I built so far are posted below. I like to cook and I love to travel. I also like to volunteer and I am a team leader with the non-profit organization, NYCares.
This entry was posted in JavaScript and tagged , , , , , , , , , , , , , , . Bookmark the permalink.