map in array code example
Example 1: array map javascript
const array1 = [1, 4, 9, 16];
const map1 = array1.map(x => x * 2);
console.log(map1);
Example 2: array map
const array1 = [1, 4, 9, 16];
const map1 = array1.map(x => x * 2);
console.log(map1);
Example 3: array map
let numbers = [1, 2, 3, 4]
let filteredNumbers = numbers.map(function(_, index) {
if (index < 3) {
return num
}
})
Example 4: array map
let numbers = [1, 4, 9]
let roots = numbers.map(function(num) {
return Math.sqrt(num)
})
Example 5: array map
let A = [{ x:'x', y:'y' }, { x:'x', y:'y' }];
let result = A.map(({y,...rest})=> ({...rest,v:y}));
console.log(result);
Example 6: map method
var yourArray= yourArray.map(Number);