Skip to content

Tag: javascript

Javascript logic to sort object based on contains logic

I have an object as shown below: {abc: value1, ab: value2, ade: value3, cde: value4, fgi: value5} I want to write a function sortByinput(input) that takes input as an argument and sort the given dictionary in such a way that the keys that include input should be sorted at top in alphabetical order and the key…

How to add value to Map initialized in state using react?

I have application and i need to keep search history, in my opinion Map is suitable here: to update it use setSearchHistory(new Map([[text, result.repos]])); but it replaces Map with new Map, could you please tell me how can i add value to Map initialized in state ? Answer State updater function returned by u…