Menu

gitpiper

mapString javascript Code Snippet in 2023

stringintermediate

Last Updated: 28 January 2023

Creates a new string with the results of calling a provided function on every character in the given string.

  • Use String.prototype.split('') and Array.prototype.map() to call the provided function, fn, for each character in str.
  • Use Array.prototype.join('') to recombine the array of characters into a string.
  • The callback function, fn, takes three arguments (the current character, the index of the current character and the string mapString was called upon).
const mapString = (str, fn) => str .split('') .map((c, i) => fn(c, i, str)) .join('');
mapString('lorem ipsum', c => c.toUpperCase()); // 'LOREM IPSUM'

javascript snippet similar to mapString For You in January 2023

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2023 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️