<prompt> Write a JavaScript function that takes in a string and returns an object with each character of the string as a key, and the number of times that character appears in the string as the value.  <response>: Here is a function that takes in a string and returns an object with the counts of each character in the string:javascriptfunction countCharsstr let result ; for let i 0; i str.length; i let char stri; if resultchar resultchar; else resultchar 1; return result;Heres an example of how you can use the function:javascriptlet string hello, world.;let charCount countCharsstring;console.logcharCount; returns : 1, ,: 1, .: 1, e: 1, h: 1, l: 3, o: 2, r: 1, w: 1 The function works by initializing an empty object. It then iterates through each character in the string using a for loop. For each character, the function checks if the character is already a key in the object. If it is, the value for that key is incremented. If the character is not yet a key in the object, the key is added with a value of 1. After the for loop completes, the function returns the object containing the counts of each character in the string. 