Javascript concepts
Sep 20, 2023
- How to access value when key name comes from a variable (V) in js object(O)?
Using square bracket ([]). For example: O[V] - Array(count).fill() — create a array of size count and fill it with undefined number can be used when for .map() or using other array properties.
- Array sorting — [].sort(() => {return boolean}) — conditional sorting js
- const frequencyMap = new Map(); Eg: Map(4) { ‘a’ => 7, ‘b’ => 5, ‘e’ => 5, ‘c’ => 2 }
— Properties ->
— has -> to check if element exist
— set -> to add the element
— enteries -> to search - ?? — nullish coalescing operator
— Returns right handside value (defaultVal) if left handside value (someVal) is null or undefined
— someVal ?? defaultVal - Javascript replace function
single replace — str.replace(/string/, ‘replacement’)
global replace — str.replace(/string/g, ‘replacement’) (g — global)