Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

square element in array

let arr = [1, 2, 3, 4, 5, 6, 7];
let square = (item) => item * item;

function arraySq(func, arr) {
    let newArr = [];
    arr.forEach((element) => {
        newArr.push(func(element));
    });
    return  newArr;
}

console.log(arraySq(square, arr));
Comment

square a array

function(arr) {

    ret= [];

    for (var i = 0, len = arr.length; i < len; i++) {
        ret.push(arr[i] * arr[i]);
    }

    return ret;     
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add new row in table on button click in javascript with next number 
Javascript :: how to take 100% width in react native 
Javascript :: js find integer 
Javascript :: js cheat sheet 
Javascript :: fetch to get data from server 
Javascript :: razor list to js array 
Javascript :: how to check if the element exist in the parent element javascript 
Javascript :: react pass variable from child to parent 
Javascript :: get element by name in jquery 
Javascript :: foreach loop js arrow functons 
Javascript :: javascript character ascii value modify 
Javascript :: usememo hook react 
Javascript :: how to disable right click of mouse on web page 
Javascript :: jsx babel webpack 
Javascript :: using underscore javascript number 
Javascript :: odd or even js 
Javascript :: capture keystrokes in javascript 
Javascript :: js default parameter 
Javascript :: remove all sign that is not a-b in string js 
Javascript :: javascript child element selector 
Javascript :: max js 
Javascript :: creating a module with lazy loading in angular 9 
Javascript :: remove all event listener from elemet 
Javascript :: how to remove last element of array in javascript 
Javascript :: save networkx graph to json 
Javascript :: sort by date javascript 
Javascript :: add google analytics to react 
Javascript :: explain the exclamation mark in js 
Javascript :: string length in javascript 
Javascript :: how to set window location search without reload 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =