Answers for "maps in javascript"

24

javascript map

array.map((item) => {
  return item * 2
} // an example that will map through a a list of items and return a new array with the item multiplied by 2
Posted by: Guest on December-22-2019
3

maps in javascript

// Map decalaration in javaScript
const obj1 = { name: 'ismail' };
const obj2 = { name: 'sulman' };
const obj3 = { name: 'naeem' };

firstMap = new Map([
    [
        [obj1, [{ date: 'yesterday', price: '10$' }]], // using object as a key in the map and object inside the array
        [obj2, [{ date: 'today', price: '100$' }]]
    ]
]);
firstMap.set(obj3, [{ date: "yesterday", price: '150$' }]); //pushing the obj to the Map

// iterating the Map
for (const entry of firstMap.entries()) {
    console.log(entry);
};

console.log(firstMap);

firstMap.delete(obj3);
console.log(firstMap);
Posted by: Guest on December-12-2020
3

initialize a map js

let map = new Map()
map['bla'] = 'blaa'
map['bla2'] = 'blaaa2'

console.log(map)  // Map { bla: 'blaa', bla2: 'blaaa2' }
Posted by: Guest on June-11-2020
4

map in javascript

// Use map to create a new array in memory. Don't use if you're not returning
const arr = [1,2,3,4]

// Get squares of each element
const sqrs = arr.map((num) => num ** 2)
console.log(sqrs)
// [ 1, 4, 9, 16 ]

//Original array untouched
console.log(arr)
// [ 1, 2, 3, 4 ]
Posted by: Guest on October-19-2020
4

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
});
Posted by: Guest on July-09-2020
2

map in javascript

let myMap = new Map()

let keyString = 'a string'
let keyObj    = {}
// setting the values
myMap.set(keyString, "value associated with 'a string'")
myMap.set(keyObj, 'value associated with keyObj')
myMap.set(keyFunc, 'value associated with keyFunc')
myMap.size              // 3
// getting the values
myMap.get(keyString)    // "value associated with 'a string'"
myMap.get(keyObj)       // "value associated with keyObj"
myMap.get(keyFunc)      // "value associated with keyFunc"
Posted by: Guest on June-21-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language