Can map be used in strings? Do I have to split a string in order to search and replace elements from it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can map be used in strings? Do I have to split a string in order to search and replace elements from it?

const htmlEntities = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;" }; For example I want to use this object in order to replace these symbols with their code from the word the user enters

19th Apr 2020, 7:26 PM
Sajid
Sajid - avatar
3 Answers
+ 2
No you don't have to use split to find and replace you can use the String method .replace() https://www.w3schools.com/jsref/jsref_replace.asp
20th Apr 2020, 7:49 PM
ODLNT
ODLNT - avatar
+ 1
map method can only be used on arrays. But split returns you an array.
20th Apr 2020, 12:16 AM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
0
Answer to second question?
20th Apr 2020, 5:41 PM
Sajid
Sajid - avatar