array.map(function(currentValue, index, arr), thisValue)
const nums = [10, 40, 62]
const newNums = nums.map(theFunc)
function theFunc(num) {
return num + 100;
}
const location = [
{ trip: 'Mexico', price: 250 },
{ trip: 'Jordan', price: 875 },
{ trip: 'Japan', price: 900 },
{ trip: 'Denmark', price: 700 }
]
const locationName = location.map((item) => {
return location.trip
return location.price
})
const numbers = [4, 2, 7, 10]
const newArr = numbers.map(function(num) {
return num * 5
})
array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
const arr = [4, 9, 15, 22]
const reducer = (accumulator, currentVal) {
return accumulator + currentVal
}, 1)
const dollars = [2.5, 10.25, .75];
const sum = dollars.reduce( function(total, amount){
return total + amount
});
sum //13.5
let val = 8
let sum = [{x: 4}, {x: 7}, {x: 1}].reduce(
(accumulator, currentVal) => accumulator + currentVal.x
, val)
array.filter(function(currentValue, index, arr), thisValue)
const ages = [18, 25, 15, 33];
function isAdult(age) {
return age >= 18;
}
let books = [
{name: 'Catcher in the rye', pages: 277},
{name: 'The House of Spirits', pages: 496},
{name: 'To Kill a Mockingbird', pages: 281},
{name: 'The Universe and the Teacup', pages: 227}
let bigBooks = books.filter(page) {
return page >= 250;
}
function positiveNum(value) {
return value > 0;
}
var filtered = [0, 333, 80, 152, 5].filter(posNum);
print(filtered);
array.forEach(function(currentValue, index, arr), thisValue)
let colors = ["black", "yellow", "red", "green", "aqua"];
function colorsAndIndex (item, index){
console.log(`${item} has index ${index}`);
}
colors.forEach(colorsAndIndex);
function sum() {
let items = [15, 33, 50];
let copy = [];
itms.forEach(function (item) {
copy.push(item + item+5);
});
document.write(copy);
}
sum();
const items = [15, 33, 50];
let copy = [];
items.forEach(function(item){
copy.push(item*item);
});
print(copy);
array.sort(compareFunction)
let famMembers = ['Jane', 'Cesar', 'Ulises', 'Maria', 'Ella'];
famMembers.sort();
let nums = [5, 21, 36, 9];
nums.sort();
let nums = [5, 21, 36, 9];
nums.sort(function(a, b){return a-b});
array.slice(start, end)
let colors = ['black', 'blue', 'teal', 'coral', 'red'];
colors.slice(0,2);
let nums = [7, 83, 39, 90, 6];
let newNums = nums.slice(3);
let users = ['Mary', 'Oliver', 'Bob', 'Gabe'];
users.slice(1, 3);
array.pop()
let iceCreamFlavors = ['strawberry', 'vanilla', 'chocolate', 'pecan', 'mocha'];
function myIceCreamOptions() {
iceCreamFlavors.pop();
function nums() { numbers.pop();
<h3>Example:</h3>
```js
<h3>Example:</h3>
```js
- Adds new items to the end of an array, and returns the new length.
array.push(item1, item2, ..., itemX)
- Adds new items to the beginning of an array, and returns the new length.
array.unshift(tem1, item2, ..., itemX)
- Determines whether a string contains the characters of a specified string. The method returns true if the string contains the characters and, false if not.
string.includes(searchvalue, start)
- Searches the array for the specified item and returns its position. The search will start at the specified position or at the beginning if no start position is specified. (Returns -1 if the item is not found.
array.indexOf(item, start)
<h3>Example:</h3>
```js
array.every(function(currentValue, index, arr), thisValue)
```js
<h3>Example:</h3>
```js
public char charAt(int index)
string.charCodeAt(index)
string.concat(string1, string2, ..., stringX)
includes(searchElement)
includes(searchElement, fromIndex)
string.indexOf(searchvalue, start)
- Searches a string for a match against a regular expression, and returns the matches, as an Array object.
The method retrieves the result by matching a string against the regular expression to return a new array.
string.match(regexp)
string.repeat(count)
string.replace(oldvalue, newvalue, count)
string.search(searchvalue)
array.splice(index, howmany, item1, ....., itemX)
string.split(separator, limit)
string.substr(start, length)
string.toLowerCase()
string.toUpperCase()
string.trim()