Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript array functions

concat(arr1,[...]) // Joins two or more arrays, and returns a copy of the joined arrays
copyWithin(target,[start],[end]) // Copies array elements within the array, to and from specified positions
entries() // Returns a key/value pair Array Iteration Object
every(function(currentval,[index],[arr]),[thisVal]) // Checks if every element in an array pass a test
fill(val,[start],[end]) // Fill the elements in an array with a static value
filter(function(currentval,[index],[arr]),[thisVal]) //	Creates a new array with every element in an array that pass a test
find(function(currentval,[index],[arr]),[thisVal]) // Returns the value of the first element in an array that pass a test
findIndex(function(currentval,[index],[arr]),[thisVal]) // Returns the index of the first element in an array that pass a test
forEach(function(currentval,[index],[arr]),[thisVal]) // Calls a function for each array element
from(obj,[mapFunc],[thisVal]) // Creates an array from an object
includes(element,[start]) // Check if an array contains the specified element
indexOf(element,[start]) // Search the array for an element and returns its position
isArray(obj) // Checks whether an object is an array
join([seperator]) // Joins all elements of an array into a string
keys() // Returns a Array Iteration Object, containing the keys of the original array
lastIndexOf(element,[start]) // Search the array for an element, starting at the end, and returns its position
map(function(currentval,[index],[arr]),[thisVal]) // Creates a new array with the result of calling a function for each array element
pop() // Removes the last element of an array, and returns that element
push(item1,[...]) // Adds new elements to the end of an array, and returns the new length
reduce(function(total,currentval,[index],[arr]),[initVal]) // Reduce the values of an array to a single value (going left-to-right)
reduceRight(function(total,currentval,[index],[arr]),[initVal]) // Reduce the values of an array to a single value (going right-to-left)
reverse() // Reverses the order of the elements in an array
shift() // Removes the first element of an array, and returns that element
slice([start],[end]) // Selects a part of an array, and returns the new array
some(function(currentval,[index],[arr]),[thisVal]) // Checks if any of the elements in an array pass a test
sort([compareFunc]) // Sorts the elements of an array
splice(index,[quantity],[item1,...]) // Adds/Removes elements from an array
toString() // Converts an array to a string, and returns the result
unshift(item1,...) // Adds new elements to the beginning of an array, and returns the new length
valueOf() // Returns the primitive value of an array
Comment

An Array Of Functions


	const fns = [()=>{console.log("first")}, ()=>{console.log("second")}, function(){console.log("third")}]

fns[0]();
/*remember the (), the function will not execute with only fns[0]*/
Comment

array of function

#include <iostream>

using namespace std;

class fish
{
public:
    fish();
    int getAge() {return age;}
    void setAge(int newage) { age = newage; }
private:
    int age;
};

fish::fish()
{
    age = 0;
}

void showAges(fish fishes[])
{
    cout << "fish 1 age is: " << fishes[0].getAge() << endl;
    cout << "fish 2 age is: " << fishes[1].getAge() << endl;
    cout << "fish 3 age is: " << fishes[2].getAge() << endl;
}

int main()
{
    fish myFish[3];

    showAges(myFish);
    cout << endl;

    myFish[0].setAge(10);
    myFish[1].setAge(20);
    myFish[2].setAge(30);

    showAges(myFish);

    cin.get();
    return 0;
}
Comment

How does array function work?

const printResult = (a, b) => {
    return a + b;
}
console.log(printResult(5, 8));
//Expected output: 13
Comment

PREVIOUS NEXT
Code Example
Javascript :: pure function 
Javascript :: vuex store in js file 
Javascript :: how to remove an object from javascript array 
Javascript :: timezone in react js 
Javascript :: jsonl parser 
Javascript :: jquery modal 
Javascript :: map & filter 
Javascript :: how to detect if javascript is disabled with javascript 
Javascript :: javascript stack 
Javascript :: var json = $.parseJSON(request.responseText); 
Javascript :: electron js 
Javascript :: .then(async 
Javascript :: fetch composition API in Vue3 
Javascript :: how to move an element to the cursor in javascript 
Javascript :: what is a heap in javascript 
Javascript :: node.js error handling 
Javascript :: jq append value to array 
Javascript :: react catch error in component 
Javascript :: react native splash screen 
Javascript :: create react app 
Javascript :: deploy node app to heroku 
Javascript :: what is auth guard in angular 
Javascript :: + operator javascript 
Javascript :: access object property dynamically javascript 
Javascript :: map duplicate keys JS 
Javascript :: get the last element of array javascript 
Javascript :: define function js 
Javascript :: variables in javascript 
Javascript :: edit message sent by discord.js 
Javascript :: anglar cli 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =