Search code examples
javascripthtmlspecial-characters

how to hide specific text from html/nodejs


example:

var request = require("request");

window.onload = function () {
    //credit card
    var headers = {
        accept: "*/*",
        "X-Api-Key": "your api key3",
    };

    var options = {
        url: "https://randommer.io/api/Card?type=visa",
        headers: headers,
    };

    function callback(error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(body);
            let yes = (JSON.stringify(body));
            document.getElementById("output").innerHTML = yes;
        }
    }

    request(options, callback);
};

but then it will come out like this.

"{"type":"Visa","date":"2027-01-24T04:50:48.4659778+00:00","fullName":"lolsk semine","cardNumber":"49223456782","cvv":"987}"

something like this I want just only the full name, cardnumber, etc none of

":/

Not showing what it is the type, the text cardnumber I want it to come out like this

"{Visa,27-01,lolsk semine, 49223456782,987}"

and this is my HTML code

<script src="scriptbr.js"></script>
<h7 id="output"></h7>

and if you are wondering I used browserify for require to work in HTML.

I'm kinda new to javascript.


Solution

  • You can use object destructuring for the jsonObject:

    const card = {
      type: body.type,
      date: body.date,
      fullname: body.fullname,
      cardNumber : body.cardNumber,
      cvv: body.cvv
    }
    

    Then stringify to make it a string,

    let output = "{${card.type},${card.date},${card.fullname},${cardNumber},${cvv}}";
    

    and then, document.getElementById('output').innerHTML = output;