What is map in javascript?
Map example in javascript:
"map() method returns a new array. map method works with an array and its parameter must need a call back as a function."
Map() method needs a callback function or object. It's the return value in the array. It works with value if you don't have value then it does not work. Also, this method maintains the value of the original array. This example created a new array Or you can send dynamic value. Then I have used a map with this new array, here I have passed a function getMap(), then the result will be shown as below:
Your Result:
Map example in javascript:
const counting = [1, 4, 9, 16];
const counts1 = counting.map(ab => ab * 3);
console.log(counts1);
// Array [3, 12, 27, 48]
const colors = ["Red", "blue", "Black"];
// pass a function to map
const newColors = colors.map(ab => ab + " Light");
console.log(newColors);
// Array ["Red Light", "blue Light", "Black Light"]
.................................................................
<script>
var numericArr ay = ["abc", "Hello", 12, 4];
var newArrValu e = numericArray.map(getMap)
function getMa p(num) {
return num + ': ';
}
document.write (newArrValue);
</script>
Result will be:
No comments:
Note: Only a member of this blog may post a comment.