mardi 13 août 2019

How can I replace these characters in the parentheses: ( { } " " \ ) from my stringified Json object with nothing

So I'm making a little game guide for a project(tft). https://chrissawma.github.io/TftGuide/ The problem is that I have a function in my code that makes a div element where the Json object is stringyfied then passed on to the innerHTML, everytime I click on it even though I tried using the '.replace' method using RegEx for special characters mentioned. (the curly braces, the left slash, and quotes). I just want a neat little caption for each description of the 'hero types' on the left column. //Sorry for the dumb var names.. was in a hurry.

PS. only the top 4 (symbols of types of heros) are enabled to work, so that's where I'm testing it and I've disabled the rest. Please play around and see what I did wrong. Thanks guys --- a young grunt.

Ive tried a lot of ways but I think i've failed to implement them correctly. If anyone can show me 1 way or another to do it. I'm grateful.

function originStat(hero, list, properti, x) {
    var list = originList;
    var genre = list[hero];
    var target = genre[properti];


    for(let obs in list) { 
      var x = x;
      if (x === undefined){
              x = 0;  } 
      final = JSON.stringify(target[x]);
  }
            var statsheet = document.createElement('div');
            var dad = document.getElementsByClassName('heroes')[1];

              statsheet.setAttribute('class', 'assassin-stats');
              statsheet.style.opacity = 1;
              // lasttoken is the string form of the object returned.
              var lasttoken = JSON.stringify(final);
                    var unwant; //unwanted strings
                    lasttoken.replace(/\{/, "");  
                    lasttoken.replace(/\}/, "");
                    lasttoken.replace(/\"/, "");
                    const actuallylasttoken= lasttoken;

                  statsheet.innerHTML = actuallylasttoken;
                  dad.appendChild(statsheet);
                  return (statsheet.innerHTML);

  }  

actual erroneous result I'm getting: "{\"needed\":3,\"effect\":\"At the start of combat, summon an Elemental. Elemental has 2200 health and 100 Attack Damage.\"}"

what I need: needed:3 effect:At the start of combat, summon an Elemental. Elemental has 2200 health and 100 Attack Damage.
OR needed:3 effect:At the start of combat, summon an Elemental. Elemental has 2200 health and 100 Attack Damage.




Aucun commentaire:

Enregistrer un commentaire