0

Error replacing result obtained from json.

Json

{
  "countries": "United States of America"
}

With this code I get the value of "countries"

 "countries" == e && ($('input[name=" +key+ "]').val(o), 
 $('#countries input').val(o),
 $("#new-tag-" + Xcountry).val(o)),

Result

United States of America

So far the code works perfectly for me, what I tried is that when finding "United States of America" ​​in the Json, I replaced it with "USA"

"countries" == e && ($('input[name=" +key+ "]').val(o), 
(o += t.name),
"United States of America" === t.name ? (o = "USA, ") : "United Kingdom" === t.name && (o = "UK, "),
$('#countries input').val(o),
$("#new-tag-" + Xcountry).val(o)),

This is where it gives me an error.

Try to find "United States of America" ​​and replace it with "USA"

  • Does this answer your question? [How to check whether a string contains a substring in JavaScript?](https://stackoverflow.com/questions/1789945/how-to-check-whether-a-string-contains-a-substring-in-javascript) – Samball Mar 17 '23 at 14:44
  • `This is where it gives me an error` what error? – James Mar 17 '23 at 17:20
  • Instead of showing me "USA" it shows me "undefined" – Franco Manuel Mar 17 '23 at 17:24

0 Answers0