Answers for "js array modify element"

1

modify array elements javascript

Using a FOR loop, write a function addNumber which adds the argument n to each 
number in the array arr and returns the updated arr:
const addNumber=(arr, n)=>{  
  let arr1=[];
  for(let i=0;i<Math.max(arr.length);i++){
    arr1.push((arr[i]||0)+n)
  }
  return arr1;
} 
console.log(addNumber([4, 5, 6], 7)); // expected log [11, 12, 13]
Posted by: Guest on December-11-2020
0

modify array js

let newArray = oldArray.map(funcToEachElem);
Posted by: Guest on April-17-2020
0

js array modify element

people[0] = "Georgie";
Posted by: Guest on March-18-2020
-1

how to modify an array

let firstNumbers = [1, 2, 3];
let secondNumbers = [4, 5, 6];
let merged = firstNumbers.concat(secondNumbers);
console.log(merged); // [1, 2, 3, 4, 5, 6]
Posted by: Guest on October-15-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language