1var seconds = new Date(year, month, day, hours, minutes, seconds, 0).getTime() / 1000;
1const posts = [
2 { id: 1, title: "Sample Title 1", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit..." },
3 { id: 2, title: "Sample Title 2", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit..." },
4 { id: 3, title: "Sample Title 3", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit..." },
5];
6// ES2016+
7// Create new array of post IDs. I.e. [1,2,3]
8const postIds = posts.map((post) => post.id);
9// Create new array of post objects. I.e. [{ id: 1, title: "Sample Title 1" }]
10const postSummaries = posts.map((post) => ({ id: post.id, title: post.title }));
11
12// ES2015
13// Create new array of post IDs. I.e. [1,2,3]
14var postIds = posts.map(function (post) { return post.id; });
15// Create new array of post objects. I.e. [{ id: 1, title: "Sample Title 1" }]
16var postSummaries = posts.map(function (post) { return { id: post.id, title: post.title }; });
1function listFruits() {
2 let fruits = ["apple", "cherry", "pear"]
3
4 fruits.map((fruit, index) => {
5 console.log(index, fruit)
6 })
7}
8
9listFruits()
10
11// https://jsfiddle.net/tmoreland/16qfpkgb/3/
1const products = [
2 { name: 'Laptop', price: 32000, brand: 'Lenovo', color: 'Silver' },
3 { name: 'Phone', price: 700, brand: 'Iphone', color: 'Golden' },
4 { name: 'Watch', price: 3000, brand: 'Casio', color: 'Yellow' },
5 { name: 'Aunglass', price: 300, brand: 'Ribon', color: 'Blue' },
6 { name: 'Camera', price: 9000, brand: 'Lenovo', color: 'Gray' },
7];
8
9const productName = products.map(product => product.name);
10console.log(productName);
11//Expected output:[ 'Laptop', 'Phone', 'Watch', 'Aunglass', 'Camera' ]
1let utilisateurs = new Map()
2
3utilisateurs.set('Mark Zuckerberg' ,{
4 email: 'mark@facebook.com',
5 poste: 'PDG',
6})
7
8utilisateurs.set ('bill Gates',{
9 email: 'billgates@notes.com' ,
10 poste : 'sauver le monde' ,
11
12})
13
14console.log(utilisateurs);
1//map() methods returns a new array
2const data = {name: "laptop", brands: ["dell", "acer", "asus"]}
3let inside_data = data.brands.map((i) => {
4 console.log(i); //dell acer asus
5});