.map(number) in javascript code example
Example 1: javascript map function
/* Answer to: "javascript map function" */
/*
<Array>.map() - One of the most useful in-built methods in JavaScript (imo).
The map() method creates a new array populated with the results of calling
a provided function on every element in the calling array.
For more information, click on the source link.
Let me make some examples of it's uses:
*/
let array = [1, 4, 9, 16];
array.map(num => num * 2); // [2, 8, 18, 32];
array.map(pounds => `£${pounds}.00`); // ["£1.00", "£4.00", "£9.00", "£16.00"];
array.map(item => Math.sqrt(item)); // [1, 2, 3, 4];
Example 2: map in js
//map() methods returns a new array
const data = {name: "laptop", brands: ["dell", "acer", "asus"]}
let inside_data = data.brands.map((i) => {
console.log(i); //dell acer asus
});